Overview
ThewithAsyncData extension creates a properly typed data atom that stores the results of successful async operations. It includes all features of withAsync and withAbort for complete async handling.
This extension is perfect for managing data fetching patterns where you need to:
- Store fetched data in an atom
- Track loading states
- Handle errors
- Abort outdated requests
Type Signature
Parameters
AsyncDataOptions
Configuration options extending
AsyncOptionsReturn Value
Returns the target extended with allAsyncExt properties plus:
Atom<InitState | State>
Atom that stores the fetched data. Updated automatically when async operations complete successfully.Includes a
reset action to reset data to initial state.Action<[reason?: any]>
Action to abort ongoing async operations (from
withAbort)Action<[], void>
Action that resets dependencies and data to initial state. Does not automatically re-fetch.
AsyncStatusAtom<State, InitState>
Status atom that includes the
data property (when status: true)Examples
Basic Data Fetching with Computed
With Initial State
Accumulating Data with mapPayload
Error Handling with Custom Type
Concurrent Request Handling
Reset and Re-fetch Pattern
Retry After Error
With Status Including Data
Use Cases
User Profile Management
Pagination with History
Related
- withAsync - Base async state tracking
- withAsyncStatus - Detailed status tracking
- withAbort - Abort handling