T
TanStack3y ago
quickest-silver

Is there a way to update a query cache after a mutation?

Like the name suggested, is there any way to update a query cache from a different component after a mutation? There is a way to do it with apollo client with GraphQL, but I'm using a REST api so is there something similar to this?
// Documentation from Apollo

const [addTodo, { data, loading, error }] = useMutation(ADD_TODO, {
refetchQueries: [
{query: GET_POST}, // DocumentNode object parsed with gql
'GetComments' // Query name
],
});
// Documentation from Apollo

const [addTodo, { data, loading, error }] = useMutation(ADD_TODO, {
refetchQueries: [
{query: GET_POST}, // DocumentNode object parsed with gql
'GetComments' // Query name
],
});
3 Replies
quickest-silver
quickest-silverOP3y ago
Thank you! I've been searching for it
generous-apricot
generous-apricot3y ago
Mastering Mutations in React Query
Learn all about the concept of performing side effects on the server with React Query.

Did you find this page helpful?