Reactive Effect.ts integration for React using effect-atom
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.
Use Atom.runtime to create a runtime pre-configured with your Provider layer:
import { Atom } from "@effect-atom/atom"import { Layer } from "effect"import { HttpProvider } from "voltaire-effect"// Create runtime with composed layersconst runtime = Atom.runtime( HttpProvider("https://eth.llamarpc.com"))
Atoms wrap Effect programs and make them reactive:
import { Atom } from "@effect-atom/atom"import { getBalance, getBlockNumber } from "voltaire-effect"// Simple atom - fetches latest block numberconst blockNumberAtom = runtime.atom(getBlockNumber)// Parameterized atom factory - returns a new atom per addressconst balanceAtom = (address: `0x${string}`) => runtime.atom(getBalance(address, "latest"))
// Get value or defaultconst balance = Result.getOrElse(result, () => 0n)// Get value or throwconst balance = Result.getOrThrow(result)// Map over success valueconst formatted = Result.map(result, (balance) => (Number(balance) / 1e18).toFixed(4))
import { useAtomValue } from "@effect-atom/atom-react"function Component() { const result = useAtomValue(myAtom) // Re-renders when atom value changes}