You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we have some methods for data fetching where we have a synchronous method that takes a callback as argument. The fetched data is then returned by that callback, like
/** Instead of */constdata=awaitSomeApiManager.fetchData();// andconst{ isLoading, error, data }=useQuery({queryKey: ['someKey'],queryFn: async()=>awaitSomeApiManager.fetchData(),})/** We have*/SomeApiManager.fetchData(res=>{// here the data can be usedconst{data, status}=res;})// andconst{ isLoading, error, data }=useQuery({queryKey: ['someKey'],queryFn: ()=>{// what to do here?}})
This is because the callback might be called not only once but several times due to refetching/ timeout/ rate limit policies. Therefore it is not possible to wait just once for the fetch to be finished (using async/await) but we have to provide the callback. Is it somehow possible to use this method call with the useQuery hook? If res.status === 'success', we know that the fetch is completed, if e.g. res.status === 'pending', it isn't done yet and the callback might be called again.
Optionally, it would be great, if we could also influence the isLoading state of the hook somehow, e.g. set it to false after the callback was executed the first time or only after the final execution.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
we have some methods for data fetching where we have a synchronous method that takes a callback as argument. The fetched data is then returned by that callback, like
This is because the callback might be called not only once but several times due to refetching/ timeout/ rate limit policies. Therefore it is not possible to wait just once for the fetch to be finished (using async/await) but we have to provide the callback. Is it somehow possible to use this method call with the
useQuery
hook? Ifres.status === 'success'
, we know that the fetch is completed, if e.g.res.status === 'pending'
, it isn't done yet and the callback might be called again.Optionally, it would be great, if we could also influence the
isLoading
state of the hook somehow, e.g. set it to false after the callback was executed the first time or only after the final execution.Thanks!
Cheers
Beta Was this translation helpful? Give feedback.
All reactions