Overview
asyncAtom is a query-style resource: a fetcher plus reactive data, isLoading, error, and status atoms. Calling the asyncAtom reads data.
Pass keys (an array of atoms) to auto-run when those keys change. Omit or pass an empty keys array for manual-only mode — then only refetch() fetches.
The fetcher receives { zero } — a ZeroPromise with .signal / .cancel() for abort. Optional debounce delays auto-run; staleTime > 0 schedules quiet background refreshes after settle.
asyncAtom vs nearby APIs
|
API
|
Role
|
Prefer when
|
|---|---|---|
asyncAtom
| Resource | Keyed/manual fetch with status — read like an atom. |
asyncAction
| Callable workflow | Invoke with args; cache/polling helpers. See Actions. |
atom + manual fetch
| DIY | Fine for one-off loads; you wire loading/error yourself. |
Keyed auto-fetch
Changing the id key re-runs the fetcher. Simulated delay + error path.
Manual refetch (no keys)
Omit keys for refetch-only resources. cancel() aborts the in-flight ZeroPromise.