T
TanStack14mo ago
foreign-sapphire

Invalidate query and wait for it to repopulate and then run a function

So as the title says, I want to invalidate the query and in the same scope ideally I would like to know when it gets populated back so I can run a function when that is finished. Another option I have in mind is to manually update the query data using a mutation and run my function in the success callback
4 Replies
rare-sapphire
rare-sapphire14mo ago
queryClient.invalidateQueries returns a Promise, so it can be awaited
foreign-sapphire
foreign-sapphireOP14mo ago
So if I await the invalidateQueries I can guarantee that the query is populated with new data - assuming everything went well
rare-sapphire
rare-sapphire14mo ago
yes, but that doesn't mean you have access of data returned from useQuery in the same closure because that's not how react works
foreign-sapphire
foreign-sapphireOP14mo ago
ok, yes, I understand that, that is good enough for my use case

Did you find this page helpful?