UNPKG

@cervello/react

Version:

🤯 Simple, reactive, tiny and performant state-management library

21 lines (20 loc) • 1.08 kB
import type { FieldPath, StoreChange } from '../../types/shared'; export type CervelloOptions<StoreValue extends Record<string, any>> = { afterChange?: (storeChange: Array<StoreChange<StoreValue>>) => void; }; export type CervelloUseStoreOptions<StoreValue extends Record<string, any>> = { initialValue?: (currentStore: StoreValue) => StoreValue | null; setValueOnMount?: (currentStore: StoreValue) => Promise<StoreValue>; select?: Array<FieldPath<StoreValue>> | (() => Array<FieldPath<StoreValue>>); onChange?: (storeChange: Array<StoreChange<StoreValue>>) => void; }; type MutableStoreValue<T extends Record<string, any>> = { $value: T; } & T; export declare function nonReactive<T extends Record<string, any>>(initialValue: T): T; export declare function cervello<StoreValue extends Record<PropertyKey, any>>(initialValue: StoreValue, options?: CervelloOptions<StoreValue>): { store: MutableStoreValue<StoreValue>; reset: () => void; useStore: (options?: CervelloUseStoreOptions<StoreValue>) => MutableStoreValue<StoreValue>; }; export {};