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
TheuseAtomValue hook reads the current value of an atom and subscribes the component to updates. The component will re-render whenever the atom’s value changes.
Signature
Parameters
The atom to read the value from. The component will subscribe to this atom and re-render when its value changes.
Optional transformation function to derive a value from the atom’s state. The transformation is memoized and creates a derived atom internally.
Returns
The current value of the atom, or the transformed value if a transformation function was provided.
Usage
Basic usage
Read a simple atom value:With transformation
Transform the atom value before using it:Reading derived state
Derive complex state from an atom:Read-only components
Create components that only read values without the ability to update:Best practices
The transformation function is memoized based on the atom reference and function reference. Use
React.useCallback to memoize the transformation function if it depends on props or other values.Related hooks
- useAtom - Read and write atom values
- useAtomSet - Write-only access to atoms
- useAtomSuspense - Read async atoms with Suspense