Skip to content

Commit 82b2827

Browse files
Merge pull request #120
2 parents 53dd9c6 + b02000c commit 82b2827

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

.codesandbox/ci.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Jotai Query 🚀 👻
22

3-
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/jotaijs/jotai-tanstack-query/tree/main/examples/01_typescript)
4-
53
[jotai-tanstack-query](https://github.com/jotai-labs/jotai-tanstack-query) is a Jotai extension library for TanStack Query. It provides a wonderful interface with all of the TanStack Query features, providing you the ability to use those features in combination with your existing Jotai state.
64

75
# Table of contents
@@ -77,6 +75,8 @@ The second optional `getQueryClient` parameter is a function that return [QueryC
7775

7876
### atomWithQuery usage
7977

78+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/jotaijs/jotai-tanstack-query/tree/main/examples/01_query)
79+
8080
`atomWithQuery` creates a new atom that implements a standard [`Query`](https://tanstack.com/query/v5/docs/react/guides/queries) from TanStack Query.
8181

8282
```jsx
@@ -104,7 +104,9 @@ const UserData = () => {
104104

105105
### atomWithQueries usage
106106

107-
`atomWithQueries` creates a new atom that implements parallel queries from TanStack Query. It allows you to run multiple queries concurrently and optionally combine their results.
107+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/jotaijs/jotai-tanstack-query/tree/main/examples/07_queries)
108+
109+
`atomWithQueries` creates a new atom that implements `Dynamic Parallel Queries` from TanStack Query. It allows you to run multiple queries concurrently and optionally combine their results. You can [read more about Dynamic Parallel Queries here](https://tanstack.com/query/v5/docs/framework/react/guides/parallel-queries#dynamic-parallel-queries-with-usequeries).
108110

109111
There are two ways to use `atomWithQueries`:
110112

@@ -201,6 +203,8 @@ const CombinedUsersData = () => {
201203

202204
### atomWithInfiniteQuery usage
203205

206+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/jotaijs/jotai-tanstack-query/tree/main/examples/03_infinite)
207+
204208
`atomWithInfiniteQuery` is very similar to `atomWithQuery`, however it is for an `InfiniteQuery`, which is used for data that is meant to be paginated. You can [read more about Infinite Queries here](https://tanstack.com/query/v5/docs/guides/infinite-queries).
205209

206210
> Rendering lists that can additively "load more" data onto an existing set of data or "infinite scroll" is also a very common UI pattern. React Query supports a useful version of useQuery called useInfiniteQuery for querying these types of lists.
@@ -245,6 +249,8 @@ const Posts = () => {
245249

246250
### atomWithMutation usage
247251

252+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/jotaijs/jotai-tanstack-query/tree/main/examples/05_mutation)
253+
248254
`atomWithMutation` creates a new atom that implements a standard [`Mutation`](https://tanstack.com/query/v5/docs/guides/mutations) from TanStack Query.
249255

250256
> Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
@@ -298,6 +304,8 @@ jotai-tanstack-query can also be used with React's Suspense.
298304

299305
### atomWithSuspenseQuery usage
300306

307+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/jotaijs/jotai-tanstack-query/tree/main/examples/02_suspense)
308+
301309
```jsx
302310
import { atom, useAtom } from 'jotai'
303311
import { atomWithSuspenseQuery } from 'jotai-tanstack-query'
@@ -320,6 +328,8 @@ const UserData = () => {
320328

321329
### atomWithSuspenseInfiniteQuery usage
322330

331+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/jotaijs/jotai-tanstack-query/tree/main/examples/04_infinite_suspense)
332+
323333
```jsx
324334
import { atom, useAtom } from 'jotai'
325335
import { atomWithSuspenseInfiniteQuery } from 'jotai-tanstack-query'
@@ -385,23 +395,11 @@ import { QueryClientProvider } from 'jotai-tanstack-query/react'
385395

386396
const queryClient = new QueryClient()
387397

388-
const HydrateAtoms = ({ children }) => {
389-
useHydrateAtoms([[queryClientAtom, queryClient]])
390-
return children
391-
}
392-
393-
export const App = () => {
398+
export const Root = () => {
394399
return (
395400
<QueryClientProvider client={queryClient}>
396401
<Provider>
397-
{/*
398-
This Provider initialisation step is needed so that we reference the same
399-
queryClient in both atomWithQuery and other parts of the app. Without this,
400-
our useQueryClient() hook will return a different QueryClient object
401-
*/}
402-
<HydrateAtoms>
403-
<App />
404-
</HydrateAtoms>
402+
<App />
405403
</Provider>
406404
</QueryClientProvider>
407405
)
@@ -457,10 +455,7 @@ $ yarn add @tanstack/react-query-devtools
457455
All you have to do is put the `<ReactQueryDevtools />` within `<QueryClientProvider />`.
458456

459457
```tsx
460-
import {
461-
QueryClient,
462-
QueryCache,
463-
} from '@tanstack/react-query'
458+
import { QueryClient, QueryCache } from '@tanstack/react-query'
464459
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
465460
import { QueryClientProvider } from 'jotai-tanstack-query/react'
466461
import { queryClientAtom } from 'jotai-tanstack-query'
@@ -473,13 +468,11 @@ const queryClient = new QueryClient({
473468
},
474469
})
475470

476-
export const App = () => {
471+
export const Root = () => {
477472
return (
478473
<QueryClientProvider client={queryClient}>
479474
<Provider>
480-
<HydrateAtoms>
481-
<App />
482-
</HydrateAtoms>
475+
<App />
483476
</Provider>
484477
<ReactQueryDevtools />
485478
</QueryClientProvider>

0 commit comments

Comments
 (0)