rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
24 lines (23 loc) • 1.01 kB
TypeScript
import React from "react";
import { type StatusChangeCallback } from "./client-core.js";
type HookDeps = {
useState: typeof React.useState;
useEffect: typeof React.useEffect;
useRef: typeof React.useRef;
useCallback: typeof React.useCallback;
};
type Setter<T> = (value: T | ((previous: T) => T)) => void;
export type CreateSyncedStateHookOptions = {
url?: string;
roomId?: string;
hooks?: HookDeps;
onStatusChange?: StatusChangeCallback;
};
/**
* Builds a `useSyncedState` hook configured with optional endpoint and hook overrides.
* @param options Optional overrides for endpoint and React primitives.
* @returns Hook that syncs state through the sync state service.
*/
export declare const createSyncedStateHook: (options?: CreateSyncedStateHookOptions) => <T>(initialValue: T, key: string, roomId?: string | undefined) => [T, Setter<T>];
export declare const useSyncedState: <T>(initialValue: T, key: string, roomId?: string | undefined) => [T, Setter<T>];
export {};