Skip to content

Commit

Permalink
chore(examples): use cancelQueries in optimistic update example
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed May 11, 2020
1 parent 52042e9 commit 4855cf7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/optimistic-updates/pages/api/data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const items = []

export default async (req, res) => {
await new Promise(r => setTimeout(r, 500))
await new Promise(r => setTimeout(r, 1000))

if (req.method === 'POST') {
const { text } = req.body
Expand Down
2 changes: 2 additions & 0 deletions examples/optimistic-updates/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default () => {
// the old value and return it so that it's accessible in case of
// an error
onMutate: text => {
queryCache.cancelQueries('todos')

const previousValue = queryCache.getQueryData('todos')

queryCache.setQueryData('todos', old => ({
Expand Down

0 comments on commit 4855cf7

Please sign in to comment.