UNPKG

statelet

Version:

Dead simple state management built on kvkit - composable, reactive, shareable. Supports Standard Schema (Valibot, Zod, ArkType).

31 lines (30 loc) 894 B
import type { State } from './index.js'; /** * React hook for using state containers in components * * @example * const userState = compose( * state({ name: '', email: '' }), * withStorage('user') * ); * * function UserForm() { * const [user, setUser] = useStatelet(userState); * * return ( * <input * value={user.name} * onChange={e => setUser(prev => ({ ...prev, name: e.target.value }))} * /> * ); * } * * @example * // With selector for performance optimization * function UserName() { * const [userName, setUser] = useStatelet(userState, state => state.name); * return <h1>{userName}</h1>; * } */ export declare function useStatelet<T, R>(state: State<T>, selector: (value: T) => R): [R, (value: T | ((prev: T) => T)) => void]; export declare function useStatelet<T>(state: State<T>): [T, (value: T | ((prev: T) => T)) => void];