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
T - The updated record
omit
Removes specified keys from the record.Array<keyof T>
Keys to remove from the record
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
T - The updated record
Basic Usage
Advanced Usage
Form State Management
User Profile with Partial Updates
Combining with Computed Atoms
Using with Atom Methods
SinceRecordAtom extends Atom, you can use standard atom methods:
Notes
mergeonly triggers updates when at least one value actually changes (usesObject.is()for comparison)omitonly triggers updates if at least one specified key exists in the recordresetwith no arguments resets the entire record to the initial stateresetwith specific keys only resets those keys to their initial values- All mutations create new object instances, preserving immutability
- Direct mutations like
recordAtom().key = valuewill not trigger updates; usemerge()orset()instead