useMutation 'invalidates' field #7324
-
From the docs:
With the removal of the onSuccess hook, something for QOL could be implemented: useMutation({
mutationFn: async () => {
await updateTodo();
// await queryClient.invalidateQueries({ queryKey: ['todos'] }); // Moved
},
invalidates: ['todos']
}); Where if the mutation succeeds, the query keys in the invalidates array are refetched automatically. Not sure if this breaks any react query methodology but just a suggestion that could save some lines as its a very common pattern. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
there are too many different cases to consider, for example:
Because of questions like this, and likely everybody expecting something slightly different depending on their use-case, we haven't implemented anything like that. That said, it's very easy to do this in user-land with
usage:
|
Beta Was this translation helpful? Give feedback.
onSuccess
wasn't removed from mutations ...there are too many different cases to consider, for example:
onSuccess
or inonSettled
?awaited
, or should they fire as background refetches. The differences determines how long the mutation itself stays in pending state.Because of questions like this, and likely everybody expecting something slightly different depending on their use-case, we haven…