Skip to content

Effect v4 Atom Solid API

Import Atom and AtomRef from Effect v4 core, and import Solid bindings from @effect/atom-solid.

import * as Atom from "effect/unstable/reactivity/Atom"
import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"
import * as AtomRef from "effect/unstable/reactivity/AtomRef"
import { RegistryProvider, useAtom } from "@effect/atom-solid"
import type { Accessor, ResourceOptions, ResourceReturn } from "solid-js"

Atom and AtomRef selection hooks accept lazy thunks where their signatures below show one, allowing them to track the selected source within Solid’s reactive ownership model. useAtomInitialValues is different: it receives the iterable directly.

Subscribes to a writable atom and returns a reactive accessor with a setter.

function useAtom<R, W>(
  atom: () => Atom.Writable<R, W>,
): readonly [Accessor<R>, (value: W | ((current: R) => W)) => void]

Subscribes to an atom and optionally derives a value.

function useAtomValue<A>(atom: () => Atom.Atom<A>): Accessor<A>
function useAtomValue<A, B>(atom: () => Atom.Atom<A>, select: (value: A) => B): Accessor<B>

Returns a setter without subscribing to the atom value.

function useAtomSet<R, W>(
  atom: () => Atom.Writable<R, W>,
): (value: W | ((current: R) => W)) => void

Subscribes a callback to atom changes.

function useAtomSubscribe<A>(
  atom: () => Atom.Atom<A>,
  callback: (value: A) => void,
  options?: { readonly immediate?: boolean },
): void
function useAtomMount<A>(atom: () => Atom.Atom<A>): void
function useAtomRefresh<A>(atom: () => Atom.Atom<A>): () => void

Seeds the first value supplied for each atom in the current registry.

function useAtomInitialValues(
  initialValues: Iterable<readonly [Atom.Atom<any>, any]>,
): void

Converts an AsyncResult atom into a Solid resource. It also accepts Solid resource options and suspendOnWaiting.

function useAtomResource<A, E>(
  atom: () => Atom.Atom<AsyncResult.AsyncResult<A, E>>,
  options?: ResourceOptions<A> & { suspendOnWaiting?: boolean },
): ResourceReturn<A, void>
function useAtomRef<A>(ref: () => AtomRef.ReadonlyRef<A>): Accessor<A>

Returns an accessor containing the derived property ref.

function useAtomRefProp<A, K extends keyof A>(
  ref: () => AtomRef.AtomRef<A>,
  property: K,
): Accessor<AtomRef.AtomRef<A[K]>>
function useAtomRefPropValue<A, K extends keyof A>(
  ref: () => AtomRef.AtomRef<A>,
  property: K,
): Accessor<A[K]>

RegistryProvider creates and disposes an AtomRegistry for a Solid subtree. It accepts initial values and optional scheduling and lifetime settings. RegistryContext exposes the current registry for lower-level integrations.