@@ -39,7 +39,7 @@ npm i jotai jotai-tanstack-query @tanstack/react-query
3939
4040``` jsx
4141import { QueryClient } from ' @tanstack/react-query'
42- import { useAtom } from ' jotai'
42+ import { useAtomValue } from ' jotai'
4343import { atomWithQuery } from ' jotai-tanstack-query'
4444import { QueryClientAtomProvider } from ' jotai-tanstack-query/react'
4545
@@ -59,7 +59,7 @@ const todosAtom = atomWithQuery(() => ({
5959}))
6060
6161const App = () => {
62- const [ { data , isPending , isError }] = useAtom (todosAtom)
62+ const { data , isPending , isError } = useAtomValue (todosAtom)
6363
6464 if (isPending) return < div> Loading... < / div>
6565 if (isError) return < div> Error < / div>
@@ -73,7 +73,7 @@ const App = () => {
7373You can incrementally adopt ` jotai-tanstack-query ` in your app. It's not an all or nothing solution. You just have to ensure you are using the [ same QueryClient instance] ( #exported-provider ) .
7474
7575``` jsx
76- // existing useQueryHook
76+ // TanStack/Query
7777const { data , isPending , isError } = useQuery ({
7878 queryKey: [' todos' ],
7979 queryFn: fetchTodoList,
@@ -84,7 +84,7 @@ const todosAtom = atomWithQuery(() => ({
8484 queryKey: [' todos' ],
8585}))
8686
87- const [ { data , isPending , isError }] = useAtom (todosAtom)
87+ const { data , isPending , isError } = useAtomValue (todosAtom)
8888```
8989
9090### Exported provider
@@ -110,32 +110,28 @@ export const Root = () => {
110110
111111Yes, you can absolutely combine them yourself.
112112
113- ``` diff
114- - import { QueryClient } from '@tanstack/react-query'
115- - import { QueryClientAtomProvider } from 'jotai-tanstack-query/react'
116- + import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
117- + import { Provider } from 'jotai/react'
118- + import { useHydrateAtoms } from 'jotai/react/utils'
119- + import { queryClientAtom } from 'jotai-tanstack-query'
113+ ``` js
114+ import { QueryClient , QueryClientProvider } from ' @tanstack/react-query'
115+ import { Provider } from ' jotai/react'
116+ import { queryClientAtom } from ' jotai-tanstack-query'
117+ import { useHydrateAtoms } from ' jotai/react/utils'
120118
121119const queryClient = new QueryClient ()
122120
123- + const HydrateAtoms = ({ children }) => {
124- + useHydrateAtoms([[queryClientAtom, queryClient]])
125- + return children
126- + }
121+ const HydrateAtoms = ({ children }) => {
122+ useHydrateAtoms ([[queryClientAtom, queryClient]])
123+ return children
124+ }
127125
128126export const Root = () => {
129127 return (
130- - <QueryClientAtomProvider client={queryClient}>
131- + <QueryClientProvider client={queryClient}>
132- + <Provider>
133- + <HydrateAtoms>
128+ < QueryClientProvider client= {queryClient}>
129+ < Provider>
130+ < HydrateAtoms>
134131 < App / >
135- + </HydrateAtoms>
136- + </Provider>
137- + </QueryClientProvider>
138- - </QueryClientAtomProvider>
132+ < / HydrateAtoms>
133+ < / Provider>
134+ < / QueryClientProvider>
139135 )
140136}
141137```
0 commit comments