UNPKG

@loke/ui

Version:
31 lines (30 loc) 1.21 kB
import { type Dispatch, type SetStateAction } from "react"; /** Function that handles state changes */ type ChangeHandler<T> = (state: T) => void; /** React's setState dispatch function type */ type SetStateFn<T> = Dispatch<SetStateAction<T>>; /** * Parameters for the useControllableState hook */ interface UseControllableStateParams<T> { /** Name of the component using this hook (for warning messages) */ caller?: string; /** The default value to use in uncontrolled mode */ defaultProp: T; /** Callback fired when the value changes */ onChange?: ChangeHandler<T>; /** * The controlled value. If provided, component is in controlled mode. * If undefined, component is in uncontrolled mode. */ prop?: T | undefined; } /** * Hook for managing state that can be either controlled or uncontrolled * * Allows components to support both controlled and uncontrolled modes. * In controlled mode, the value is provided by the parent component. * In uncontrolled mode, the value is managed internally. */ export declare function useControllableState<T>({ prop, defaultProp, onChange, caller, }: UseControllableStateParams<T>): [T, SetStateFn<T>]; export {};