UNPKG

@trellixio/roaster-coffee

Version:
38 lines 1.73 kB
interface UseUncontrolledInput<T> { /** Value for controlled state */ value?: T; /** Initial value for uncontrolled state */ defaultValue?: T; /** Final value for uncontrolled state when value and defaultValue are not provided */ finalValue?: T; /** Controlled state onChange handler */ onChange?(value: T): void; } /** * A custom React hook that provides a value, a function to update the value, and a flag that indicates whether the value is controlled or not. * This hook is designed to provide a flexible input component that can be controlled or uncontrolled. * * @typeParam T - The type of the input value. * @param value - The value of the input for a controlled component. * @param defaultValue - The initial value of the input for an uncontrolled component. * @param finalValue - The final value of the input for an uncontrolled component when `value` and `defaultValue` are not provided. * @param onChange - The callback function that is called when the input value changes in a controlled component. * @returns A tuple containing the input value, a function to update the input value, and a flag that indicates whether the input value is controlled. * * @example * ```tsx * function MyInput({ value, onChange }) { * const [inputValue, setInputValue, isControlled] = useUncontrolled({ value, onChange }); * * return ( * <input * value={isControlled ? value : inputValue} * onChange={(e) => setInputValue(e.target.value)} * /> * ); * } *``` */ export declare function useUncontrolled<T>({ value, defaultValue, finalValue, onChange, }: UseUncontrolledInput<T>): [T, (value: T) => void, boolean]; export {}; //# sourceMappingURL=index.d.ts.map