Installation
Overview
Effect Atoms provide a reactive state management solution that seamlessly integrates Effect programs with React. Atoms represent pieces of state that can be read, written, and derived from other atoms.Basic Usage
Creating Atoms
Create a simple atom with an initial value:Reading and Writing Atoms
UseuseAtom to both read and write atom values:
Derived Atoms
Create atoms that derive their value from other atoms:Async Atoms
Atoms can contain Effect programs for async operations:Suspense Support
UseuseAtomSuspense for React Suspense integration:
Registry Provider
Wrap your app withRegistryProvider to manage atom state:
Initial Values
Provide initial values for atoms:Server-Side Rendering (SSR)
Hydration
Support for React 18+ hydration:Scoped Atoms
Create atoms with specific scopes:Effect Integration
Atoms work seamlessly with Effect’s runtime and layers:Atom Families
Create parameterized atoms:Hooks Reference
useAtomValue
Read an atom’s value:useAtom
Read and write an atom:useAtomSet
Get only the setter function:useAtomSuspense
Use with React Suspense:useAtomRef
Use with AtomRef:Best Practices
- Atom Granularity: Create small, focused atoms rather than large state objects
- Derived State: Use derived atoms instead of duplicating state
- Async Operations: Leverage AsyncResult for proper loading/error states
- Registry Provider: Always wrap your app with RegistryProvider
- Error Boundaries: Use React Error Boundaries with async atoms
API Modules
- Hooks: React hooks for atoms (useAtom, useAtomValue, etc.)
- RegistryContext: Registry context and provider
- ReactHydration: SSR hydration support
- ScopedAtom: Scoped atom utilities
