T
TanStack10mo ago
conscious-sapphire

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?
No description
5 Replies
robust-apricot
robust-apricot10mo ago
useQueryClient()
robust-apricot
robust-apricot10mo 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-sapphire
conscious-sapphireOP10mo ago
so it's not available as part of the query? i'd expect it to be but ok
rare-sapphire
rare-sapphire10mo ago
context in the context of a mutation is whatever you return from onMutate It's not the queryClient.
conscious-sapphire
conscious-sapphireOP10mo ago
Oh I see, that wasn't really clear, thanks.

Did you find this page helpful?