Skip to main content

Overview

The withComputed extension enhances an atom with computed functionality, allowing you to derive state based on reactive dependencies. It’s a powerful way to add computed behavior to existing atoms without converting them to computed atoms.

Type Signature

Parameters

function
required
A function that computes the new state based on the current state.Parameters:
  • state: The current state of the atom
Returns: The computed state
object

Examples

Basic Computed for Atom

Manual Update with Computed Fallback

Combining Multiple Computations

Conditional Computed

Transform State

Sync Atom with External Source

Computed with Dependencies Check

Use Cases

Default Value Pattern

Fallback Chain

Derived State with Manual Override