Reset a query back to idle and rerender #1027
Replies: 4 comments 12 replies
-
|
I think you can pull the https://react-query.tanstack.com/reference/useQuery (remove is down at the bottom). That should reset isIdle and isSuccess to the pre-fetched status and force a re-render. |
Beta Was this translation helpful? Give feedback.
-
|
I too would love to have this feature added. I've been using different approaches to achieve this:
The former is a bit annoying since need to use |
Beta Was this translation helpful? Give feedback.
-
you can return a
the |
Beta Was this translation helpful? Give feedback.
-
as written in their docs |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using a
useQuerywithenabled: falsefor a user search, triggering the request usingrefetch. I want to offer a Reset button that will remove the existing query and rerender the form: basically resetting everything back to the initialidlestate.I can use
queryCache.invalidateQueries("key")to invalidate the query but am struggling to find an elegant way to rerender when that happens. When usinguseMutationhowever, you can callresetand this seems to do the trick. However, in this case I am using aGETwhereuseMutationfeels like the wrong fit.How are other people managing this pattern?
e.g.
Beta Was this translation helpful? Give feedback.
All reactions