/** * The options for the `useControlledState` hook. */ export interface UseControlledStateOptions { /** * The value of the controlled state. */ value?: T | undefined; /** * The default value of the uncontrolled state. */ defaultValue?: T | undefined; /** * Callback function that is called when the value changes. */ onChange?: (newValue: E) => void; } /** * The updater form accepted by the `useControlledState` setter. * Receives the current value and whether the state is controlled. */ export type UseControlledStateUpdater = (prev: T | undefined, controlled: boolean) => unknown; /** * The setter returned by the `useControlledState` hook. * Accepts either a resolved value or an updater function. */ export interface UseControlledStateSetter { (updater: UseControlledStateUpdater): void; (inValue: unknown): void; } /** * The return type of the `useControlledState` hook. * A tuple containing the current value and a function to update it. */ export type UseControlledStateReturnType = [T | undefined, UseControlledStateSetter, boolean]; /** * A custom hook that manages controlled and uncontrolled state. * * @param {UseControlledStateOptions} options - The options for the controlled state. * @returns A tuple containing the current value and a function to update it. * * @example * ```tsx * const ControlledComponent = () => { * const [controlledValue, setControlledValue] = React.useState(''); * * const [value, setValue] = useControlledState({ * value: controlledValue, * defaultValue: 'initial value', * onChange: (newValue) => { * setControlledValue(newValue); * } * }); * * return setValue(e.target.value)} />; * }; * ``` */ export declare function useControlledState({ value, defaultValue, onChange }: UseControlledStateOptions): UseControlledStateReturnType;