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
wee-brown•16mo ago
queryClient.invalidateQueries returns a Promise, so it can be awaitedfascinating-indigoOP•16mo ago
So if I await the invalidateQueries I can guarantee that the query is populated with new data - assuming everything went well
wee-brown•16mo 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
fascinating-indigoOP•16mo ago
ok, yes, I understand that, that is good enough for my use case