UNPKG

react-understate

Version:

A lightweight, reactive signals library for React 18+ with automatic dependency tracking and optimized performance

24 lines (20 loc) 844 B
interface State<T> { readonly rawValue: T; update(fn: (prev: T) => T | Promise<T>): Promise<void>; subscribe(fn: () => void): () => void; get value(): T; set value(newValue: T | ((prev: T) => T | Promise<T>)); get requiredValue(): NonNullable<T>; set requiredValue(newValue: NonNullable<T>); } declare function state<T>(initialValue: T, name?: string): State<T>; declare function batch(fn: () => void, name?: string): void; declare function derived<T>(computeFn: () => T, name?: string): State<T>; type EffectOptions = { once?: boolean; preventOverlap?: boolean; preventLoops?: boolean; }; declare function effect(fn: () => void | (() => void) | Promise<void> | Promise<() => void>, name?: string, options?: EffectOptions): () => void; export { batch, derived, effect, state }; export type { State };