@@ -26,25 +26,8 @@ async function fetchTodos(): Promise<Todos> {
26
26
return res . data
27
27
}
28
28
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 )
48
31
}
49
32
50
33
function Example ( ) {
@@ -129,7 +112,7 @@ function Example() {
129
112
</ >
130
113
) }
131
114
{ queryInfo . isLoading && 'Loading' }
132
- { queryInfo . error ? .message }
115
+ { queryInfo . error instanceof Error && queryInfo . error . message }
133
116
</ div >
134
117
)
135
118
}
@@ -138,7 +121,6 @@ export default function App() {
138
121
return (
139
122
< QueryClientProvider client = { client } >
140
123
< Example />
141
- < TodoCounter />
142
124
< ReactQueryDevtools initialIsOpen />
143
125
</ QueryClientProvider >
144
126
)
0 commit comments