Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tim-smart/effect-atom/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheuseAtomSet hook provides a setter function for writing values to an atom. Unlike useAtom, it only returns the setter and doesn’t subscribe to value changes, making it more efficient for write-only scenarios.
Signature
Parameters
A writable atom that can accept values of type
W and stores values of type R.Configuration options for the setter behavior.
Determines the return type of the setter function:
"value"(default): Returnsvoid, synchronous updates"promise": Returns a promise that resolves to the result value"promiseExit": Returns a promise that resolves to anExit(includes failures)
Returns
A memoized setter function whose signature depends on the
mode option:- Default mode:
(value: W | ((current: R) => W)) => void- Updates the atom synchronously - Promise mode:
(value: W) => Promise<Result.Success<R>>- Returns a promise of the updated value - PromiseExit mode:
(value: W) => Promise<Exit>- Returns a promise with the full exit status
Usage
Basic synchronous updates
Update an atom with a new value:Functional updates
Update based on the current value:Promise mode for async atoms
Wait for async atoms to complete:PromiseExit mode for error handling
Handle both success and failure cases:Write-only form controls
Components that only update state:Best practices
The setter function is memoized and remains stable across re-renders. You can safely pass it to child components or use it in dependency arrays.
Use
useAtomSet instead of useAtom when you only need to write to an atom. This prevents unnecessary re-renders when the atom value changes.Related hooks
- useAtom - Read and write atom values
- useAtomValue - Read-only access to atoms
- useAtomSuspense - Read async atoms with Suspense