Skip to content

RegistryContext

React context and provider for the Atom registry used by Effect Atom hooks. The registry stores atom values, schedules update work, and cleans up unused atoms. Sharing one registry through React context lets components in the same subtree read and write the same atom state.

3 exports Added in v4.0.0 Source

Context

Provides a React context that supplies the AtomRegistry used by Atom hooks and hydration helpers, defaulting to a standalone registry when no provider is present.

When to use

Use to supply an existing AtomRegistry through React context when hooks or hydration helpers need to share registry state that is managed outside RegistryProvider.

See

Signature

declare const RegistryContext: Context<AtomRegistry>;

Provides a stable AtomRegistry to a React subtree, optionally seeding initial atom values and overriding registry scheduling or idle settings.

When to use

Use to scope atom state, scheduling, and idle cleanup to a React subtree.

Details

The provider creates one AtomRegistry with AtomRegistry.make, passes it through RegistryContext.Provider, and forwards initialValues, scheduleTask, timeoutResolution, and defaultIdleTTL only when that registry is created.

Gotchas

Option changes after the first render do not rebuild the registry. When the provider unmounts, registry disposal is delayed briefly and canceled if the provider remounts before the timeout fires.

See

Signature

declare function RegistryProvider(options: {
  readonly children?: ReactNode;
  readonly defaultIdleTTL?: number;
  readonly initialValues?: Iterable<readonly [Atom<any>, any], any, any>;
  readonly scheduleTask?: (f: () => void) => () => void;
  readonly timeoutResolution?: number;
}): FunctionComponentElement<ProviderProps<AtomRegistry>>;

scheduleTask

Added in v4.0.0 Source

Schedules Atom registry work with React's scheduler at low priority and returns a cancellation function for the scheduled task.

Signature

declare function scheduleTask(f: () => void): () => void;