Skip to content

Commit 4855cf7

Browse files
committed
chore(examples): use cancelQueries in optimistic update example
1 parent 52042e9 commit 4855cf7

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

examples/optimistic-updates/pages/api/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const items = []
22

33
export default async (req, res) => {
4-
await new Promise(r => setTimeout(r, 500))
4+
await new Promise(r => setTimeout(r, 1000))
55

66
if (req.method === 'POST') {
77
const { text } = req.body

examples/optimistic-updates/pages/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default () => {
1717
// the old value and return it so that it's accessible in case of
1818
// an error
1919
onMutate: text => {
20+
queryCache.cancelQueries('todos')
21+
2022
const previousValue = queryCache.getQueryData('todos')
2123

2224
queryCache.setQueryData('todos', old => ({

0 commit comments

Comments
 (0)