useAtomValue is a React hook that reads the value of an atom. It subscribes to the atom and triggers a re-render when the atom’s value changes.
When to use it
UseuseAtomValue when you only need to read an atom’s value without modifying it. This is more efficient than useAtom when you don’t need the setter function.
Signature
Parameters
atom: The atom to read fromoptions: Optional configuration objectstore: Custom store to use (defaults to the store from Provider)delay: Delay in milliseconds before re-renderingunstable_promiseStatus: Enable promise status tracking (experimental)
Returns
The current value of the atom. If the atom value is a promise, it will be awaited using React Suspense.Basic Usage
With Async Atoms
useAtomValue works seamlessly with async atoms using React Suspense:
With Derived Atoms
Comparison with useAtom
useAtomValue is more efficient than useAtom when you don’t need to update the atom:
Delay Option
Thedelay option can help batch updates or wait for async values:
TypeScript
useAtomValue is fully typed and infers the atom’s value type: