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 2222 const addMutation = createMutation ({
2323 mutationFn : (value : string ) =>
2424 fetch (` ${endpoint }?add=${value } ` ).then ((r ) => r .json ()),
25- onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ]}),
25+ onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ] }),
2626 })
2727
2828 const clearMutation = createMutation ({
2929 mutationFn : () => fetch (` ${endpoint }?clear=1 ` ).then ((r ) => r .json ()),
30- onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ]}),
30+ onSuccess : () => client .invalidateQueries ({ queryKey: [' refetch' ] }),
3131 })
3232 </script >
3333
Original file line number Diff line number Diff line change 4646 onMutate : async (newTodo : string ) => {
4747 text = ' '
4848 // Cancel any outgoing refetches (so they don't overwrite our optimistic update)
49- await client .cancelQueries ({queryKey: [' optimistic' ]})
49+ await client .cancelQueries ({ queryKey: [' optimistic' ] })
5050
5151 // Snapshot the previous value
5252 const previousTodos = client .getQueryData <Todos >([' optimistic' ])
7272 },
7373 // Always refetch after error or success:
7474 onSettled : () => {
75- client .invalidateQueries ({queryKey: [' optimistic' ]})
75+ client .invalidateQueries ({ queryKey: [' optimistic' ] })
7676 },
7777 })
7878 </script >
Original file line number Diff line number Diff line change 1212
1313 let name = ' '
1414
15- const postTodo = async ({ name , notes }: { name: string , notes: string }) => {
15+ const postTodo = async ({ name , notes }: { name: string ; notes: string }) => {
1616 console .info (' postTodo' , { name , notes })
1717 return new Promise ((resolve , reject ) => {
1818 setTimeout (() => {
Original file line number Diff line number Diff line change 1212 editingIndex ,
1313 } from ' ../lib/stores'
1414
15- type Todo = { id: number , name: string , notes: string }
15+ type Todo = { id: number ; name: string ; notes: string }
1616
1717 const queryClient = useQueryClient ()
1818
You can’t perform that action at this time.
0 commit comments