Async Data
Async Data (@ekz/async-data) models the lifecycle of asynchronous values — loading, success, failure, and stale cached data — in a type-safe container inspired by functional patterns.
It pairs well with @ekz/option for optional values and is used throughout the @ekz libraries (for example in @ekz/api).
Why use it?
- Explicit states instead of ad-hoc
loading/error/databooleans - Stale-while-revalidate via
PendingStaleandFailedStale matchAPI for exhaustive renderingobservePromiseto wire promises into React state safely
States
| State | Meaning |
|---|---|
Empty | No value yet |
Pending | Loading, no previous value |
Ready | Success with a value |
PendingStale | Reloading, showing previous value |
Failed | Error, no previous value |
FailedStale | Error after a previous value was loaded |
Install
npm install @ekz/async-data @ekz/option
# or
yarn add @ekz/async-data @ekz/option
Peer dependency: @ekz/option ^2.
Next steps
- Getting started — create and transition states
- States — state machine details
- Promises —
observePromisein React - Extractors —
@ekz/async-data/extractors