-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conditional execution of the request #245
Comments
I'm still trying to think of a good way to do conditional fetching with auto-managed state. For now, what you can do is const { data, get } = useFetch(MatchApi.GET_EVENTS(matchId, mapId))
useEffect(() => {
const shouldFetch = !(typeof matchId === 'undefined' && typeof mapId === 'undefined')
if (shouldFetch) get()
}, [matchId, mapId, get]) OR const { data, get } = useFetch()
useEffect(() => {
const shouldFetch = !(typeof matchId === 'undefined' && typeof mapId === 'undefined')
if (shouldFetch) get(MatchApi.GET_EVENTS(matchId, mapId))
}, [matchId, mapId, get]) Ideas for solving this via "auto-managed state"
const shouldFetch = !(typeof matchId === 'undefined' && typeof mapId === 'undefined')
const path = shouldFetch ? MatchApi.GET_EVENTS(matchId, mapId) : null
const matchDetails = useFetch<MapEvents>(path, [matchId, mapId, shouldFetch])
const shouldFetch = !(typeof matchId === 'undefined' && typeof mapId === 'undefined')
const matchDetails = useFetch<MapEvents>(MatchApi.GET_EVENTS(matchId, mapId), {
skip: !shouldFetch,
}, [matchId, mapId, shouldFetch]) Thoughts? |
I'm gonna hold off on this until I get more feedback from this poll. |
Seems like having a |
having skip would be similar to apollo-client. i think its a must for auto managed state |
So according to the poll, having a |
I think I have this implemented somewhere in one of the branches |
Hi,
I have a component that makes a request for data depending on the data it gets from its parent in props, and these also come from an external API. I want to avoid conditional rendering of the component, because I've already made a beautiful skeleton loader for this component! 😄 What I would like to be able to do is to make the conditional request only when the value needed to execute the request is not undefined. This way my component is listening to the two flags informing about the data loading.
What I tried so far looked more or less like this, but for obvious reasons it makes one unnecessary request.
The text was updated successfully, but these errors were encountered: