Installation
Overview
Effect Atoms provide a reactive state management solution that seamlessly integrates Effect programs with SolidJS. 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:Registry Provider
Wrap your app withRegistryProvider to manage atom state:
Initial Values
Provide initial values for atoms:Effect Integration
Atoms work seamlessly with Effect’s runtime and layers:Atom Families
Create parameterized atoms:Working with AsyncResult
Handle different states of async atoms:Promise Mode
Get promises from atom updates:Hooks Reference
useAtomValue
Read an atom’s value as a Solid signal:useAtom
Read and write an atom:useAtomSet
Get only the setter function:useAtomRef
Use with AtomRef:Best Practices
- Reactive Atoms: Use functions when atoms need to be reactive:
useAtomValue(() => atom) - Atom Granularity: Create small, focused atoms rather than large state objects
- Derived State: Use derived atoms instead of duplicating state
- Async Operations: Use AsyncResult helper functions for proper state handling
- Registry Provider: Always wrap your app with RegistryProvider
- Error Handling: Use SolidJS’s ErrorBoundary with async atoms
SolidJS-Specific Features
Reactive Atoms
SolidJS’s fine-grained reactivity works perfectly with atoms:Cleanup
Atoms automatically clean up when components unmount thanks to SolidJS’s reactive system:API Modules
- Hooks: SolidJS hooks for atoms (useAtom, useAtomValue, etc.)
- RegistryContext: Registry context and provider
