Skip to main content

Function Signature

Creates a reactive atom that manages asynchronous operations. The atom automatically tracks the state of the promise (pending, done, or error) and updates subscribers when the promise resolves or rejects.

Parameters

() => Promise<T>
required
An async function that returns a Promise. This function is called immediately when the atom is created and whenever the atom is recomputed (if it depends on other atoms).
AtomOptions<AsyncAtomState<T>>
Optional configuration for the atom.

Return Type

ReadonlyAtom<AsyncAtomState<T>>
Returns a readonly atom containing the async operation state. The state is a discriminated union:

Examples

Basic Async Atom

Handling All States

Subscribing to Async State Changes

Reactive Async Atoms

Error Handling

TypeScript Error Types

Combining Multiple Async Atoms

Retry Logic

Key Features

Automatic State Tracking

Tracks pending, success, and error states automatically without manual state management.

Type-Safe States

TypeScript discriminated unions ensure type safety when accessing data or error properties.

Reactive Dependencies

Automatically refetches when dependent atoms change, keeping async data fresh.

Observable Updates

Subscribers are notified when the async operation completes or fails.