effect-io-ai

Package: @effect/atom-react
Module: Hooks

Hooks.useAtom

Subscribes to a writable atom and returns its current value together with a setter for updating it.

When to use

Use when a React component needs both to render the current value of a writable atom and update it from the same component.

See

Signature

declare const useAtom: <R, W, const Mode extends "value" | "promise" | "promiseExit" = never>(atom: Atom.Writable<R, W>, options?: { readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined; }) => readonly [value: R, write: "promise" extends Mode ? ((value: W) => Promise<AsyncResult.AsyncResult.Success<R>>) : "promiseExit" extends Mode ? ((value: W) => Promise<Exit.Exit<AsyncResult.AsyncResult.Success<R>, AsyncResult.AsyncResult.Failure<R>>>) : ((value: W | ((value: R) => W)) => void)]

Source

Since v4.0.0