useHydrateAtoms
Hydrates atom values, typically used for server-side rendering (SSR) or initializing atoms with values on mount.Import
Signature
Parameters
An iterable of atom-value pairs to hydrate. Can be:
- Array of tuples:
[[atom1, value1], [atom2, value2]] - Map:
new Map([[atom1, value1], [atom2, value2]]) - Any iterable of tuples
Optional configuration:
store: Specify a custom store to usedangerouslyForceHydrate: Iftrue, forces re-hydration even if atoms were already hydrated
Returns
void - This hook does not return a value.
Usage
Server-Side Rendering (SSR)
Using with Map
Force Re-hydration
Hydration Only Happens Once
By default, atoms are only hydrated once. Subsequent calls touseHydrateAtoms with the same atoms will be ignored:
TypeScript Type Safety
The hook ensures type safety between atoms and their values:Related APIs
- Provider - Provide a Jotai store to components
- useStore - Access the current store
- useSetAtom - Set atom values imperatively