From 260d37b79bb314102d18cc9506fd4dfa0577a82f Mon Sep 17 00:00:00 2001 From: Kier Borromeo Date: Sun, 8 Jun 2025 18:45:12 +0800 Subject: [PATCH 1/3] Updates examples for invalidation from mutations --- .../react/guides/invalidations-from-mutations.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/framework/react/guides/invalidations-from-mutations.md b/docs/framework/react/guides/invalidations-from-mutations.md index 6f0e75537f..a9cdb81c70 100644 --- a/docs/framework/react/guides/invalidations-from-mutations.md +++ b/docs/framework/react/guides/invalidations-from-mutations.md @@ -27,9 +27,15 @@ const queryClient = useQueryClient() // When this mutation succeeds, invalidate any queries with the `todos` or `reminders` query key const mutation = useMutation({ mutationFn: addTodo, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ['todos'] }) - queryClient.invalidateQueries({ queryKey: ['reminders'] }) + onSuccess: async () => { + // If you're invalidating a single query + await queryClient.invalidateQueries({ queryKey: ['todos'] }) + + // If you're invalidating multiple queries + await Promise.all([ + queryClient.invalidateQueries({ queryKey: ['todos'] }), + queryClient.invalidateQueries({ queryKey: ['reminders'] }) + ]) }, }) ``` From 3000d93fc2e178d5f08ca951eaaa3fb2cdf55eb3 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 8 Jun 2025 10:48:45 +0000 Subject: [PATCH 2/3] ci: apply automated fixes --- docs/framework/react/guides/invalidations-from-mutations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/framework/react/guides/invalidations-from-mutations.md b/docs/framework/react/guides/invalidations-from-mutations.md index a9cdb81c70..ca137d0b97 100644 --- a/docs/framework/react/guides/invalidations-from-mutations.md +++ b/docs/framework/react/guides/invalidations-from-mutations.md @@ -34,7 +34,7 @@ const mutation = useMutation({ // If you're invalidating multiple queries await Promise.all([ queryClient.invalidateQueries({ queryKey: ['todos'] }), - queryClient.invalidateQueries({ queryKey: ['reminders'] }) + queryClient.invalidateQueries({ queryKey: ['reminders'] }), ]) }, }) From 79c4e81c182370e3f217a50947970ab0a3551201 Mon Sep 17 00:00:00 2001 From: Kier Borromeo Date: Sun, 8 Jun 2025 18:51:11 +0800 Subject: [PATCH 3/3] Elaborate promise --- docs/framework/react/guides/invalidations-from-mutations.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/framework/react/guides/invalidations-from-mutations.md b/docs/framework/react/guides/invalidations-from-mutations.md index ca137d0b97..7788b5eab9 100644 --- a/docs/framework/react/guides/invalidations-from-mutations.md +++ b/docs/framework/react/guides/invalidations-from-mutations.md @@ -42,4 +42,8 @@ const mutation = useMutation({ [//]: # 'Example2' +Returning a Promise on `onSuccess` makes sure the data is updated before the mutation is entirely complete (i.e., isPending is true until onSuccess is fulfilled) + +[//]: # 'Example2' + You can wire up your invalidations to happen using any of the callbacks available in the [`useMutation` hook](../mutations.md)