Skip to content
Discussion options

You must be logged in to vote

what you need to do is make the queryClient stable, when you create it inside a react component. You can do this with refs or with state (not with useMemo). I've blogged about this here: https://tkdodo.eu/blog/use-state-for-one-time-initializations

I prefer using state:

function App() {
  const snackbar = useSnackbar()
  const [queryClient] = React.useState(() => new QueryClient({
     queryCache: new QueryCache({
        onSuccess: (query) => snackbar.show(query)
      })
   }))
}

inside the query client creation, you can closure over snackbar. You can also extract that to an external function, doesn't really matter.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hoo00nn
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