In v0.8.0, the API was simplified to be more consistent with TanStack Query. The primary changes involve moving from returning tuples of atoms to returning a single atom that contains the full result object.
1. Atom Signature and Naming
Functions have been renamed from plural atomsWith... to singular atomWith... because they now return a single atom instead of a tuple.
2. atomWithQuery and atomWithInfiniteQuery migration
Previously, these returned [dataAtom, statusAtom]. Now, they return a single atom that provides the full QueryObserverResult<TData, TError>.
Old way:
- const [dataAtom, statusAtom] = atomsWithQuery(/* ... */);
- const [data] = useAtom(dataAtom);
- const [status] = useAtom(statusAtom);
New way:
+ const dataAtom = atomWithQuery(/* ... */);
+ const [{ data, isPending, isError }] = useAtom(dataAtom);
3. atomWithMutation migration
Previously, atomsWithMutation returned a tuple. Now, atomWithMutation returns a single atom containing the MutationObserverResult and the mutate function.
Old way:
- const [, postAtom] = atomsWithMutation(/* ... */);
- const [post, mutate] = useAtom(postAtom);
New way:
+ const postAtom = atomWithMutation(/* ... */);
+ const [{ data, error, mutate }] = useAtom(postAtom);
- const [dataAtom, statusAtom] = atomsWithQuery(/* ... */);
- const [data] = useAtom(dataAtom);
- const [status] = useAtom(statusAtom);
+ const dataAtom = atomWithQuery(/* ... */);
+ const [{ data, isPending, isError }] = useAtom(dataAtom);