Skip to content

Commit 0ac0bb4

Browse files
committed
docs: onSettled callbacks
1 parent 5f36041 commit 0ac0bb4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

docs/react/reference/MutationCache.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ Its available methods are:
3636
- Optional
3737
- This function will be called if some mutation is successful.
3838
- If you return a Promise from it, it will be awaited
39+
- `onSettled?: (data: unknown | undefined, error: unknown | null, variables: unknown, context: unknown, mutation: Mutation) => Promise<unknown> | unknown`
40+
- Optional
41+
- This function will be called if some mutation is settled (either successful or errored).
42+
- If you return a Promise from it, it will be awaited
3943
- `onMutate?: (variables: unknown, mutation: Mutation) => Promise<unknown> | unknown`
4044
- Optional
4145
- This function will be called before some mutation executes.
4246
- If you return a Promise from it, it will be awaited
4347

4448
## Global callbacks
4549

46-
The `onError`, `onSuccess` and `onMutate` callbacks on the MutationCache can be used to handle these events on a global level. They are different to `defaultOptions` provided to the QueryClient because:
50+
The `onError`, `onSuccess`, `onSettled` and `onMutate` callbacks on the MutationCache can be used to handle these events on a global level. They are different to `defaultOptions` provided to the QueryClient because:
4751

4852
- `defaultOptions` can be overridden by each Mutation - the global callbacks will **always** be called.
4953
- `onMutate` does not allow returning a context value.

docs/react/reference/QueryCache.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const queryCache = new QueryCache({
1616
},
1717
onSuccess: data => {
1818
console.log(data)
19-
}
19+
},
20+
onSettled: (data, error) => {
21+
console.log(data, error)
22+
},
2023
})
2124

2225
const query = queryCache.find({ queryKey: ['posts'] })
@@ -37,10 +40,13 @@ Its available methods are:
3740
- `onSuccess?: (data: unknown, query: Query) => void`
3841
- Optional
3942
- This function will be called if some query is successful.
43+
- `onSettled?:` (data: unknown | undefined, error: unknown | null, query: Query) => void
44+
- Optional
45+
- This function will be called if some query is settled (either successful or errored).
4046

4147
## Global callbacks
4248

43-
The `onError` and `onSuccess` callbacks on the QueryCache can be used to handle these events on a global level. They are different to `defaultOptions` provided to the QueryClient because:
49+
The `onError`, `onSuccess` and `onSettled` callbacks on the QueryCache can be used to handle these events on a global level. They are different to `defaultOptions` provided to the QueryClient because:
4450
- `defaultOptions` can be overridden by each Query - the global callbacks will **always** be called.
4551
- `defaultOptions` callbacks will be called once for each Observer, while the global callbacks will only be called once per Query.
4652

0 commit comments

Comments
 (0)