rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
23 lines (22 loc) • 907 B
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.
* Uses the raw WebSocket transport.
*/
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 {};