effect-atom provides first-class React integration for Effect.ts, making it easy to use voltaire-effect in React applications with automatic dependency injection, caching, and reactive updates.
Installation
Setup
Wrap your app with RegistryProvider to enable atom reactivity:
Creating a Runtime with Layers
Use Atom.runtime to create a runtime pre-configured with your Provider layer:
Creating Atoms
Atoms wrap Effect programs and make them reactive:
Using Atoms in Components
Basic Usage with useAtomValue
Result Builder Pattern
For more complex rendering, use the builder pattern:
Result Type
The Result type represents async operation states:
Result Refinements
Result Accessors
React Hooks Reference
useAtomValue
Read the current value of an atom reactively:
useAtomSet
Get a setter function for writable atoms:
useAtom
Combined read and write access:
useAtomRefresh
Manually trigger re-execution of an effectful atom:
useAtomSuspense
Use with React Suspense for cleaner loading states:
Derived Atoms
Create atoms that derive from other atoms:
Multiple Chains
Create separate runtimes for different networks:
Next.js Setup
App Router
Atoms Module
Using in Pages
Advanced: Scoped Effects with Cleanup
Atoms automatically manage Effect scopes, running finalizers when unmounted:
Error Handling
Handle errors using Result pattern matching:
Best Practices
Atom MemoizationParameterized atom factories return new atoms each call. Memoize when needed:
Server Componentseffect-atom hooks require client components. Use "use client" directive in Next.js App Router.
Resources