Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update to v5 syntax #57

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ You can incrementally adopt `jotai-tanstack-query` in your app. It's not an all

```jsx
# existing useQueryHook
const { data, isLoading, isError } = useQuery('todos', () => fetch('/todos'));
const { data, isPending, isError } = useQuery({
queryKey: ['todos'],
queryFn: fetchTodoList
});

# jotai-tanstack-query
const todosAtom = atomWithQuery(() => ({
queryKey: ['todos'],
}))

const [{ data, isLoading, isError }] = useAtom(todosAtom)
const [{ data, isPending, isError }] = useAtom(todosAtom)

```

Expand Down Expand Up @@ -410,7 +413,7 @@ In the previous version of `jotai-tanstack-query`, the query atoms `atomsWithQue
#### atomWithQuery and atomWithInfiniteQuery

- `dataAtom` was used to access the actual data (`TData`).
- `statusAtom` provided the status object (`QueryObserverResult<TData, TError>`), which included additional attributes like `isLoading`, `isError`, etc.
- `statusAtom` provided the status object (`QueryObserverResult<TData, TError>`), which included additional attributes like `isPending`, `isError`, etc.

In v0.8.0, they have been replaced by `atomWithQuery` and `atomWithInfiniteQuery` to return only a single `dataAtom`. This `dataAtom` now directly provides the `QueryObserverResult<TData, TError>`, aligning it closely with the behavior of Tanstack Query's bindings.

Expand All @@ -422,7 +425,7 @@ To migrate to the new version, replace the separate `dataAtom` and `statusAtom`
- const [status] = useAtom(statusAtom);

+ const dataAtom = atomWithQuery(/* ... */);
+ const [{ data, isLoading, isError }] = useAtom(dataAtom);
+ const [{ data, isPending, isError }] = useAtom(dataAtom);
```

#### atomWithMutation
Expand Down