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.
Context
RegistryContext
Signature
declare const RegistryContext: Context<AtomRegistry>;RegistryProvider
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
RegistryContextfor the React context supplied by this provider
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
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;
Provides a React context that supplies the
AtomRegistryused by Atom hooks and hydration helpers, defaulting to a standalone registry when no provider is present.When to use
Use to supply an existing
AtomRegistrythrough React context when hooks or hydration helpers need to share registry state that is managed outsideRegistryProvider.See
RegistryProviderfor creating and providing a registry for a React subtree