You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+167-2Lines changed: 167 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -340,7 +340,24 @@ const Posts = () => {
340
340
341
341
> Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
342
342
343
+
`atomWithMutation` supports all options from TanStack Query's [`useMutation`](https://tanstack.com/query/v5/docs/react/reference/useMutation), including:
344
+
-`mutationKey` - A unique key for the mutation
345
+
-`mutationFn` - The function that performs the mutation
346
+
-`onMutate` - Called before the mutation is executed (useful for optimistic updates)
347
+
-`onSuccess` - Called when the mutation succeeds
348
+
-`onError` - Called when the mutation fails
349
+
-`onSettled` - Called when the mutation is settled (either success or error)
350
+
-`retry` - Number of retry attempts
351
+
-`retryDelay` - Delay between retries
352
+
-`gcTime` - Time until inactive mutations are garbage collected
353
+
- And all other [MutationOptions](https://tanstack.com/query/v5/docs/react/reference/useMutation#options)
`atomWithMutation` fully supports optimistic updates through the `onMutate`, `onError`, and `onSettled` callbacks. This allows you to update the UI immediately before the server responds, and roll back if the mutation fails.
For more details on optimistic updates, see the [TanStack Query Optimistic Updates guide](https://tanstack.com/query/v5/docs/framework/react/guides/optimistic-updates).
538
+
374
539
### atomWithMutationState usage
375
540
376
541
`atomWithMutationState` creates a new atom that gives you access to all mutations in the [`MutationCache`](https://tanstack.com/query/v5/docs/react/reference/useMutationState).
0 commit comments