useEffect on cache invalidation?
Hello, Is it possible to use the
queryClient to detect a specific cache being invalidated.
I have something like this in mind. Sorry If this is a bad question. I have spent a lot of time looking but cannot find the solution.
4 Replies
rising-crimson•3y ago
hi, can you maybe ask the question in a way that describes your use-case rather than asking for a niche problem solution. I think if I understood the problem, we might come to a completely different solution
vicious-goldOP•3y ago
Thanks, TkDodo. Yes certainly. I am building a self-contained component with an API call triggered when its cache gets invalided (from a component). The issue I'm having is that it needs to poll the API every few seconds until the data is returned completed. So my current solution looks something like this. There is a little more nuance but this is the basic premise.
So my main issue is that I want to set
shouldPoll to true when chacheName is invalided from an external componentrising-crimson•3y ago
refetchInterval can take a function as an argument to do this
vicious-goldOP•3y ago
🫢 That makes too much sense! Thanks!