UNPKG

@diginet/use-reactive

Version:

A reactive state management hook for React.

45 lines 1.86 kB
export type SC<T> = (this: T, state: T, key: string | number | Symbol, value: unknown, previous: unknown, read?: boolean) => void; export type S<T> = (targets: () => unknown | unknown[], callback: SC<T>, recursive?: boolean | 'deep', onRead?: boolean) => () => void; export type E<T> = (this: T, state: T, subscribe: S<T>, history: H<T>) => void | (() => void); export interface RO<T> { init?: (this: T, state: T, subscribe: S<T>, history: H<T>) => void; effects?: Array<[E<T>, (this: T, state: T, subscribe: S<T>, history: H<T>) => unknown[]]>; historySettings?: HistorySettings; noUseState?: boolean; } export interface H<T> { enable(enabled?: boolean, maxDepth?: number): HistorySettings; undo(index?: number): void; redo(all?: boolean): void; revert(index: number): void; snapshot(): string | null; restore(id: string | null): void; clear(): void; entries: HE<T>[]; } export interface HE<T> { id: string; timestamp: number; obj: object; key: keyof T; previous: unknown; value: unknown; } export interface HistorySettings { enabled?: boolean; maxDepth?: number; } /** * useReactive - A custom React hook that creates a reactive state object. * * This hook provides a proxy-based reactive state that triggers re-renders * when properties change. It also supports computed properties (getters), * hot module reloading (HMR) synchronization, and optional side effects. * * @param inputState - The initial state object. * @param effect - Optional effect function that runs when dependencies change. * @param deps - Dependencies array for triggering reactivity updates. * @returns A reactive proxy of the state object. */ export declare function useReactive<T extends object>(inputState: T, options?: RO<T>): [T, S<T>, H<T>]; //# sourceMappingURL=useReactive.d.ts.map