Open likwid23 opened 4 years ago
As answered in the other question:
const { data = {} } = useQuery(FETCH_POST_QUERY, { variables: { postId, }, }); const thisPost = data.getPost;
....
let postMarkup; if (!thisPost) { postMarkup =
Loading Post...
; } else { const { id, body, createdAt, username, // comments, likes, likeCount, commentCount, } = thisPost;
Works but gets stuck on Loading...
@aindriu80 you have to return only datalike this: const { data } = useQuery(FETCH_POST_QUERY, { variables: { postId, }, });
@likwid23 @aindriu80 the best fix I figured out is just pass an empty object to the singlePost() function then assign the destructed data to it:
function SinglePost(props,args={}) { const postId = props.match.params.postId; const { user } = useContext(AuthContext); const commentInputRef = useRef(null); const [comment, setComment] = useState(''); const{ data:{getPost} = args } = useQuery(FETCH_POST, { variables: { postId } });
... const { loading, data } = useQuery(FETCH_POST, { variables: { postId, }, })
let getPost if (!loading) { getPost = data.getPost }
...
I did this and it worked without any error
const postId = props.match.params.postId const { user } = useContext(AuthContext) const { loading, data} = useQuery(FETCH_POST_QUERY, { variables: {postId} } ) if (loading){return (
Loading
)}; //this is where i added a lineand then just define postMarkup and continue like he does.
@likwid23 @aindriu80 the best fix I figured out is just pass an empty object to the singlePost() function then assign the destructed data to it:
function SinglePost(props,args={}) { const postId = props.match.params.postId; const { user } = useContext(AuthContext); const commentInputRef = useRef(null); const [comment, setComment] = useState(''); const{ data:{getPost} = args } = useQuery(FETCH_POST, { variables: { postId } });
Thank you so much for this solution!! working fine for me.
× TypeError: Cannot read property 'getPost' of undefined
const { data: { getPost } } = useQuery(FETCH_POST_QUERY, { variables: { postId