Last active
December 2, 2019 18:23
-
-
Save jsoneaday/ff7e24602aa1aa8616447d553aedb7cd to your computer and use it in GitHub Desktop.
show usage of useLazyQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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