Any global event that is fired before a query/mutation starts executing? #3123
-
If using react-query, is there any way to check isLoading at a global level.. just like react-query has provided us with the global onError callback? I guess there is no such event handler that is fired just before the query/mutation execution is about to take place, named something like onBefore. If not there, could you pl. add it in next release? I know that React.Suspense can be used but it is kinda experimental and React does not recommend to use it. How about your opinion, can we use Suspense in a production app where there will be about 100 queries and mutations resulting in a lot of boilerplate if Loading is handled locally? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
what would be your use-case please? For mutations, there is a global For queries, we have no "before" callback. I think you can right now use a global |
Beta Was this translation helpful? Give feedback.
-
The use case is as follows: As you said, there is a global onMutate callback, can we use it to check isLoading for "all" mutations that exist in our app... and place isLoading locally? Thanks |
Beta Was this translation helpful? Give feedback.
-
If it's about showing a global loading spinner, then callbacks are not the right thing, as they are for side effects. What you are looking for is a way to show a global loading spinner, and there are two options for queries:
|
Beta Was this translation helpful? Give feedback.
-
Thanks But from where to invoke the useIsFetching and useIsMutating hook? I wrote this code:
{ useNetworkRequestInProgress && } But where to place this piece of code, I cannot figure it out. By placing it at the top of the React component tree i,e, where we put , will it work? I am avoid Suspense for single reason, React says it is still experimental. But I have seen many people use it. |
Beta Was this translation helpful? Give feedback.
If it's about showing a global loading spinner, then callbacks are not the right thing, as they are for side effects.
What you are looking for is a way to show a global loading spinner, and there are two options for queries:
predicate
filter function and only include queries where data is undefined or the state is loading.