File tree Expand file tree Collapse file tree 4 files changed +6
-6
lines changed
auto-refetching/src/routes
optimistic-updates-typescript/src/routes Expand file tree Collapse file tree 4 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 22
22
const addMutation = createMutation ({
23
23
mutationFn : (value : string ) =>
24
24
fetch (` ${endpoint }?add=${value } ` ).then ((r ) => r .json ()),
25
- onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ]}),
25
+ onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ] }),
26
26
})
27
27
28
28
const clearMutation = createMutation ({
29
29
mutationFn : () => fetch (` ${endpoint }?clear=1 ` ).then ((r ) => r .json ()),
30
- onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ]}),
30
+ onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ] }),
31
31
})
32
32
</script >
33
33
Original file line number Diff line number Diff line change 46
46
onMutate : async (newTodo : string ) => {
47
47
text = ' '
48
48
// Cancel any outgoing refetches (so they don't overwrite our optimistic update)
49
- await client .cancelQueries ({queryKey: [' optimistic' ]})
49
+ await client .cancelQueries ({ queryKey: [' optimistic' ] })
50
50
51
51
// Snapshot the previous value
52
52
const previousTodos = client .getQueryData <Todos >([' optimistic' ])
72
72
},
73
73
// Always refetch after error or success:
74
74
onSettled : () => {
75
- client .invalidateQueries ({queryKey: [' optimistic' ]})
75
+ client .invalidateQueries ({ queryKey: [' optimistic' ] })
76
76
},
77
77
})
78
78
</script >
Original file line number Diff line number Diff line change 12
12
13
13
let name = ' '
14
14
15
- const postTodo = async ({ name , notes }: { name: string , notes: string }) => {
15
+ const postTodo = async ({ name , notes }: { name: string ; notes: string }) => {
16
16
console .info (' postTodo' , { name , notes })
17
17
return new Promise ((resolve , reject ) => {
18
18
setTimeout (() => {
Original file line number Diff line number Diff line change 12
12
editingIndex ,
13
13
} from ' ../lib/stores'
14
14
15
- type Todo = { id: number , name: string , notes: string }
15
+ type Todo = { id: number ; name: string ; notes: string }
16
16
17
17
const queryClient = useQueryClient ()
18
18
You can’t perform that action at this time.
0 commit comments