Skip to content

Commit 61fd539

Browse files
committed
docs(examples): fix optimistic-updates-typescript example
1 parent 4253ff3 commit 61fd539

File tree

1 file changed

+3
-21
lines changed
  • examples/optimistic-updates-typescript/pages

1 file changed

+3
-21
lines changed

examples/optimistic-updates-typescript/pages/index.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,8 @@ async function fetchTodos(): Promise<Todos> {
2626
return res.data
2727
}
2828

29-
function useTodos<TData = Todos>(
30-
options?: UseQueryOptions<Todos, AxiosError, TData>
31-
) {
32-
return useQuery(['todos'], fetchTodos, options)
33-
}
34-
35-
function TodoCounter() {
36-
// subscribe only to changes in the 'data' prop, which will be the
37-
// amount of todos because of the select function
38-
const counterQuery = useTodos({
39-
select: data => data.items.length,
40-
notifyOnChangeProps: ['data'],
41-
})
42-
43-
React.useEffect(() => {
44-
console.log('rendering counter')
45-
})
46-
47-
return <div>TodoCounter: {counterQuery.data ?? 0}</div>
29+
function useTodos() {
30+
return useQuery(['todos'], fetchTodos)
4831
}
4932

5033
function Example() {
@@ -129,7 +112,7 @@ function Example() {
129112
</>
130113
)}
131114
{queryInfo.isLoading && 'Loading'}
132-
{queryInfo.error?.message}
115+
{queryInfo.error instanceof Error && queryInfo.error.message}
133116
</div>
134117
)
135118
}
@@ -138,7 +121,6 @@ export default function App() {
138121
return (
139122
<QueryClientProvider client={client}>
140123
<Example />
141-
<TodoCounter />
142124
<ReactQueryDevtools initialIsOpen />
143125
</QueryClientProvider>
144126
)

0 commit comments

Comments
 (0)