Missing context type in mutation callbacks
I would like to invalidate a query in
onSuccess, and the docs claim the third argument is a context, but actually it doesn't exist (see screenshot).
How do I really get access to the query client to do invalidation in this onSuccess?
5 Replies
robust-apricot•10mo ago
useQueryClient()robust-apricot•10mo ago
useQueryClient | TanStack Query React Docs
The useQueryClient hook returns the current QueryClient instance. tsx import { useQueryClient } from '@tanstack/react-query' const queryClient = useQueryClient(queryClient?: QueryClient) Options query...
conscious-sapphireOP•10mo ago
so it's not available as part of the query? i'd expect it to be but ok
rare-sapphire•10mo ago
context in the context of a mutation is whatever you return from onMutate
It's not the queryClient.
conscious-sapphireOP•10mo ago
Oh I see, that wasn't really clear, thanks.