ScopedAtom
React helpers for creating Atom instances that belong to one component subtree. make returns a scoped atom with a provider, context, and use accessor. Each provider creates its own Atom once, so different subtrees can use the same scoped atom definition without sharing state.
Constructors
Models
ScopedAtom interface
Added in v4.0.0
Source
Scoped Atom interface with a provider-backed instance.
Signature
interface ScopedAtom<A extends Atom.Atom<any>, Input = never> {
readonly "~@effect/atom-react/ScopedAtom": "~@effect/atom-react/ScopedAtom";
Context: Context<A>;
Provider: [Input] extends [never]
? FC<{
readonly children?: ReactNode;
}>
: FC<{
readonly children?: ReactNode;
readonly value: Input;
}>;
use(): A;
}Type IDs
Type identifier for ScopedAtom.
Details
Used as the computed property key and marker value stored on ScopedAtom objects.
Signature
declare const TypeId: "~@effect/atom-react/ScopedAtom";Literal type used as the ScopedAtom type identifier.
Details
Used as the computed property key and marker value stored on ScopedAtom objects.
Signature
type TypeId = "~@effect/atom-react/ScopedAtom";
Creates a ScopedAtom from a factory function.
When to use
Use to create an atom instance that is owned by a React provider and scoped to a component subtree.
Details
The returned scoped atom includes a
Provider,Context, anduseaccessor. The provider creates the atom once for its lifetime, passing thevalueprop to the factory when the scoped atom expects input.Gotchas
usemust run under the matching provider. Changing the providervalueprop after mount does not recreate the atom.