Invalidate query in clientAction/clientLoader in Remix #7491
Replies: 2 comments 1 reply
-
If you use SSR, you can't really create a global queryClient because that would be shared between requests. You can do what we recommend for nextJs:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response, unfortunately it doesn't seem to work for my case. Let me explain: I'm creating the queryClient as you mentioned in a useState in my root component: const [queryClient] = React.useState(() => getQueryClient()); This queryClient has all the data the app needs to work (it is prefetched on root loader) Then I import the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have implemented react query with SSR in Remix following this guide: https://tanstack.com/query/latest/docs/framework/react/guides/ssr#full-remix-example and using this package https://github.com/maplegrove-io/use-dehydrated-state as recommended in the guide.
However, I'm encountering an issue with invalidating query data on a Remix clientAction. Here is an example:
That doesn't work because because queryClient is not available inside the clientAction (it is inside a useState state as recommended in the guide). The queryClient can be used in react code with useQueryClient, but it can't be inside a clientAction. Any approach/suggestion to solve this? Thanks in advance! 😄
Beta Was this translation helpful? Give feedback.
All reactions