UNPKG

@ryujaewan/restate

Version:

React State (`@ryujaewan/restate` is a lightweight library that simplifies state management in React applications. It enables easy sharing and updating of state across multiple components.)

40 lines (31 loc) 1.05 kB
import { Dispatch, SetStateAction } from 'react'; export type UpdateOnType = 'alwaysUpdate' | 'topLevelChange' | 'anyLevelChange'; export interface RestateOptions { updateOn?: UpdateOnType; } export interface UpdaterProps<T> { setState: Dispatch<SetStateAction<T>>; value: T; } export interface UpdaterFunction<T> { (props: UpdaterProps<T>): (() => void) | void; } export type MemoCheckFunction<T> = (prev: T, next: T) => boolean; export interface UseRestateOptions<T> extends RestateOptions { memoCheck?: MemoCheckFunction<T>; } export interface UseRestateFn<T> { (options?: UseRestateOptions<T> | MemoCheckFunction<T>): T; get(): T; set(value: T | ((currentValue: T) => T)): void; } export declare function restate<T>( initialValue: T, updater: UpdaterFunction<T>, options?: RestateOptions ): UseRestateFn<T>; export const updateOnTypes: { alwaysUpdate: 'alwaysUpdate'; topLevelChange: 'topLevelChange'; anyLevelChange: 'anyLevelChange'; };