V5: setting global state
In V5, the onSuccess callback was removed from useQuery, but I need to set the global state after I receive the data. Is there a better alternative other then using useEffect and monitoring data?
7 Replies
xenial-black•2y ago
QueryClient has onSuccess option
sunny-green•2y ago
I have to question that need. Why do you "need to set global state after receiving data" ?
genetic-orangeOP•2y ago
I am receiving a workspaceId that will be used nearly everywhere throughout the app (even outside react components and hooks), so I wouldn't want to call that useQuery hook all the time but store it in a persisted global state
sunny-green•2y ago
what's bad about calling useQuery hook all the time ?
genetic-orangeOP•2y ago
Because I can't use it outside react components and hooks so I would have to use localStorage outside them, while I can just use this global state manager everywhere.
sunny-green•2y ago
you can use
queryClient.getQueryData(key)
everywhere
just saying: duplicating state is often a source for bugs. if it's really what you want, you can write to wherever you want directly from the queryFn
genetic-orangeOP•2y ago
Nah, the getQueryData is what I need, thanks!