Invalidating a query from outside React context
Is there some reason I can't trigger
queryClient.invalidateQueries() from outside the React context, like a timer or a socket.io listener?
One use case is a session timer that periodically checks to see if the session is about to expire, so I can pop up a dialog. I'm seeing some strange things with queries not getting updated when I invalidate from my timer.
I also want to be able to invalidate data when I get messages from a web socket, which is a similar problem.4 Replies
afraid-scarlet•3y ago
Why would you think that this is not possible?
correct-apricotOP•3y ago
Just having some challenges with it. Sounds like my issue is something else.
I haven't quite had time to reduce this to a repro case.
I've got some kind of race condition where I invalidate the session status while the rendering is happening, but it's not re-rendering with the final result until I call invalidate again.
It looks like calling
queryClient.invalidateQueries(['session']) in a root-level timer doesn't take right away. but if I instead set up a timer to call it, it works setTimeout(() => queryClient.invalidateQueries(['session']), 0)
What would you suggest to create a repro case?afraid-scarlet•3y ago
Yeah can you show that in a reproduction?
correct-apricotOP•3y ago
Working on it...