Skip to content

Best way to execute side-effects based on query's result? #8931

Answered by TkDodo
shinobu-uwu asked this question in Q&A
Discussion options

You must be logged in to vote

I have to navigate to another page

navigation can be done declaratively in most routing libraries:

const { data } = useQuery(...)

if (shouldRedirect(data) {
  return <Navigate to=“...” />
}

I must remove it from the zustand store

Not sure why the item is in the zustand store, but you can do that either from within the queryFn or in an effect.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@shinobu-uwu
Comment options

Answer selected by shinobu-uwu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants