Installation
Overview
Effect Atoms provide a reactive state management solution that seamlessly integrates Effect programs with Vue 3. 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
Provide a custom registry to your Vue app:Initial Values
Provide initial values when creating the registry: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:Composables Reference
useAtomValue
Read an atom’s value as a Vue ref:useAtom
Read and write an atom:useAtomSet
Get only the setter function:useAtomRef
Use with AtomRef:injectRegistry
Get the current atom registry:Best Practices
- Use Functions: Always pass atoms as functions to composables:
useAtomValue(() => atom) - Atom Granularity: Create small, focused atoms rather than large state objects
- Derived State: Use derived atoms instead of computed properties when possible
- Async Operations: Use AsyncResult helper functions for proper state handling
- Registry Injection: Provide registry at app level for consistency
- TypeScript: Enable strict mode for better type inference
Vue-Specific Features
Reactive Atoms
Vue’s reactivity system works seamlessly with atoms:Cleanup
Atoms automatically clean up when components unmount:Composition API
Create reusable atom composables:API Modules
- AtomRegistry: Re-exported from effect
- AsyncResult: Re-exported from effect
- Atom: Re-exported from effect
- AtomRef: Re-exported from effect
- AtomHttpApi: Re-exported from effect
- AtomRpc: Re-exported from effect
