Skip to main content

Overview

The withSuspense extension adds suspense support to async atoms by creating a suspended computed atom that tracks resolved values from promises. It’s designed to work seamlessly with React Suspense boundaries. The suspended atom will:
  • Return the resolved value immediately if the promise is already fulfilled
  • Throw the promise if it’s still pending (allowing Suspense boundaries to catch it)
  • Propagate errors if the promise is rejected
  • Automatically update when the promise resolves

Type Signature

Parameters

object

Return Value

Computed<Awaited<State>>
Computed atom that returns the resolved value or throws the promise/error

Examples

Basic Suspense

Using withSuspense Extension

React Suspense Integration

Error Handling with Suspense

Preserve Previous State

withSuspenseInit

Enables asynchronous initialization for synchronous atoms:

Unwrap Promise Type

Async Initializer Callback

Typed Async Init

settled Helper

Check if a promise is settled and get its value:

suspense Helper

Automatically apply withSuspense and get suspended value:

Use Cases

Data Fetching with Suspense

Conditional Suspense

Local-First Pattern

Progressive Enhancement