Skip to main content

Overview

reatomRecord creates an atom that manages record (object) state with built-in methods for merging partial updates, omitting keys, and resetting to initial values. It’s ideal for managing form state, settings, or any structured object data.

Import

Type Signature

Parameters

Exclude<T, Fn>
required
The initial record/object value. Must be a plain object (not a function)
string
default:"'recordAtom'"
Optional name for the atom, useful for debugging

Methods

merge

Merges a partial update into the record. Only triggers an update if at least one value has changed.
Partial<T>
A partial object with keys to update
Returns: T - The updated record

omit

Removes specified keys from the record.
Array<keyof T>
Keys to remove from the record
Returns: T - The updated record with keys removed

reset

Resets specified keys (or all keys if none specified) to their initial values.
Array<keyof T>
Keys to reset. If empty, resets the entire record to initial state
Returns: T - The updated record

Basic Usage

Advanced Usage

Form State Management

User Profile with Partial Updates

Combining with Computed Atoms

Using with Atom Methods

Since RecordAtom extends Atom, you can use standard atom methods:

Notes

  • merge only triggers updates when at least one value actually changes (uses Object.is() for comparison)
  • omit only triggers updates if at least one specified key exists in the record
  • reset with no arguments resets the entire record to the initial state
  • reset with specific keys only resets those keys to their initial values
  • All mutations create new object instances, preserving immutability
  • Direct mutations like recordAtom().key = value will not trigger updates; use merge() or set() instead