Skip to content

Commit 3064422

Browse files
keyurgovraniTkDodoautofix-ci[bot]
authored
docs: fix ignored promise from invalidate queries (#8847)
* fix(examples): Promise returned from invalidateQueries being ignored in optimistic-updates-cache example * fix(examples): Promise returned from invalidateQueries is ignored in optimistic-updates-ui example * fix(docs): Promise returned from invalidateQueries is ignored in optimistic-updates documentation * Update docs/framework/react/guides/optimistic-updates.md Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc> * refactor(docs, examples): standardize queryClient.invalidateQueries syntax in all onSettled callbacks * ci: apply automated fixes --------- Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent f45205f commit 3064422

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

docs/framework/react/guides/optimistic-updates.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ const addTodoMutation = useMutation({
1616
mutationFn: (newTodo: string) => axios.post('/api/data', { text: newTodo }),
1717
// make sure to _return_ the Promise from the query invalidation
1818
// so that the mutation stays in `pending` state until the refetch is finished
19-
onSettled: async () => {
20-
return await queryClient.invalidateQueries({ queryKey: ['todos'] })
21-
},
19+
onSettled: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
2220
})
2321

2422
const { isPending, submittedAt, variables, mutate, isError } = addTodoMutation
@@ -121,9 +119,7 @@ useMutation({
121119
queryClient.setQueryData(['todos'], context.previousTodos)
122120
},
123121
// Always refetch after error or success:
124-
onSettled: () => {
125-
queryClient.invalidateQueries({ queryKey: ['todos'] })
126-
},
122+
onSettled: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
127123
})
128124
```
129125

@@ -159,9 +155,8 @@ useMutation({
159155
)
160156
},
161157
// Always refetch after error or success:
162-
onSettled: (newTodo) => {
163-
queryClient.invalidateQueries({ queryKey: ['todos', newTodo.id] })
164-
},
158+
onSettled: (newTodo) =>
159+
queryClient.invalidateQueries({ queryKey: ['todos', newTodo.id] }),
165160
})
166161
```
167162

@@ -175,7 +170,7 @@ You can also use the `onSettled` function in place of the separate `onError` and
175170
useMutation({
176171
mutationFn: updateTodo,
177172
// ...
178-
onSettled: (newTodo, error, variables, context) => {
173+
onSettled: async (newTodo, error, variables, context) => {
179174
if (error) {
180175
// do something
181176
}

examples/react/optimistic-updates-cache/src/pages/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ function Example() {
7575
}
7676
},
7777
// Always refetch after error or success:
78-
onSettled: () => {
79-
queryClient.invalidateQueries({ queryKey: ['todos'] })
80-
},
78+
onSettled: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
8179
})
8280

8381
return (

0 commit comments

Comments
 (0)