T
TanStack•3y ago
absent-sapphire

How to use onSuccess or onSettled in useQueries ?

Am I missing anything ? checked terminal console and browser console, no data is printing. PS: Api calling are happening on server side
No description
3 Replies
flat-fuchsia
flat-fuchsia•3y ago
Hi 👋 I think this has been raised before, see: https://github.com/TanStack/query/issues/3459 Callbacks happen when requests (or whatever you're doing in the query function) happen. If you're expecting these callbacks to run in the browser (after pre-fetching on the server) when hydration occurs, I don't think that'll happen. What are you trying to achieve? Some more context and a use case would be helpful here.
absent-sapphire
absent-sapphireOP•3y ago
Got it, we can't use onSuccess if we're fetching data in server using dehydrate. Actually I wanted to get called onSuccess function, so that I can perform some action after getting the result. As currently that function is not being called, that's why I am using useEffect instead
flat-fuchsia
flat-fuchsia•3y ago
The callback functions are only called after the query function runs. If you are pre-fetching on the server then the query function won't run on the client unless you run the query function again. If you can provide more context we might be able to advise but I'm glad you've got it working :reactquery:

Did you find this page helpful?