-
In my app, I have a socket.io client that receives messages that indicate updates to server data. When I receive a message, I need to either invalidate the cache for related queries, or better yet, update the cache directly with data received via the socket. However, in my socket client, I don't see how I can access queryClient to trigger the cache update/invalidate. Is there a way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I'll add that I can declare the queryClient in App.js as
And use window.queryClient in my socket.io client, but this feels like a bit of a hack. Would love a more "front door" solution. |
Beta Was this translation helpful? Give feedback.
-
you create a - const queryClient = new QueryClient()
+ export const queryClient = new QueryClient() there are reasons why this can be troublesome in some cases, which I have listed here: So I think you can also setup the socket io client in the react app lifecycle to gain access to the |
Beta Was this translation helpful? Give feedback.
you create a
queryClient
somewhere, so you can most certainly export and import it:there are reasons why this can be troublesome in some cases, which I have listed here:
So I think you can also setup the socket io client in the react app lifecycle to gain access to the
queryClient
withuseQueryClient
. But you don't have to - it's just about weighing tradeoffs.