Skip to content

Instantly share code, notes, and snippets.

@jsoneaday
Last active December 2, 2019 18:23
Show Gist options
  • Save jsoneaday/ff7e24602aa1aa8616447d553aedb7cd to your computer and use it in GitHub Desktop.
Save jsoneaday/ff7e24602aa1aa8616447d553aedb7cd to your computer and use it in GitHub Desktop.
show usage of useLazyQuery
const [
execGetThreadData,
{ called, data: getThreadData, error, loading, refetch }
] = useLazyQuery(GetThread);
useEffect(() => {
if (called && loading) {
log("thread is loading");
} else if (error) {
log(error);
} else if (!called && !getThreadData && id) {
execGetThreadData({
variables: { id, incViewCount: true }
});
} else if (called && getThreadData) {
if (thread == getThreadData.getThread) {
refetch({ id, incViewCount: true });
} else {
setThread(getThreadData.getThread);
}
}
}, [getThreadData, id, userProfile]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment