ActionObserver
Mediator class between the useAction hook and ConnectivityClient. Not typically used directly.
Role
- One instance per hook (
useState, stable reference) setOptions()for in-place option updates (re-registers action without remount)subscribeandgetCurrentResultconnect directly touseSyncExternalStoreexecute()delegates toConnectivityClientand invokes callbacks
Signature
class ActionObserver<TInput = unknown, TResult = unknown> {
constructor(
client: ConnectivityClient,
options: ActionOptionsConfig<TInput, TResult>,
defaultActionOptions?: Partial<ActionOptions>,
);
setOptions(options: ActionOptionsConfig<TInput, TResult>, defaults?: Partial<ActionOptions>): void;
setCallbacks(callbacks?: UseActionCallbacks<TResult>): void;
subscribe(callback: () => void): () => void;
getCurrentResult(): { pendingCount: number; lastError: unknown };
execute(input: TInput): Promise<
| { enqueued: true; jobId: string }
| { enqueued: false; result: TResult }
| undefined
>;
}Memoization
getCurrentResult() returns a new reference only when pendingCount or lastError actually changes. This prevents unnecessary re-renders from useSyncExternalStore.
Related
Last updated on