hightable
Version:
A dynamic windowed scrolling table component for react
37 lines (36 loc) • 1.8 kB
TypeScript
/**
* Props for the useInputState hook.
* @param value the external value. If undefined, the input is uncontrolled and has a local state. This value cannot be unset (undefined) later if controlled, or set to a value if uncontrolled.
* @param onChange the callback to call when the input changes. If undefined, the input is read-only.
* @param defaultValue the default value for the local state if the input is uncontrolled.
* @param disabled true if the input is disabled. In this case, the value is undefined and the result onChange function does nothing.
*/
interface UseInputStateProps<T> {
value?: T;
onChange?: ((value: T) => void);
defaultValue?: T;
disabled?: boolean;
}
/**
* Result of the useInputState hook.
*
* @param value the current input value
* @param onChange the callback to call when the input changes. undefined if the input cannot be changed by the user.
*/
interface UseInputStateResult<T> {
value?: T;
onChange?: ((value: T) => void);
}
/**
* Simulates the state of React <input> components. See https://react.dev/reference/react-dom/components/input#controlling-an-input-with-a-state-variable
*
* The input state can be:
* - controlled (if value is defined): the parent controls the value. No local state.
* - uncontrolled (if value is undefined): the input controls the value. Local state.
* - disabled: the value is hidden and the user interactions are disabled. No local state.
*
* Note that the onChange prop can be defined or undefined. If undefined in a controlled state, the input is read-only (no interactions),
* else, the input can change but the parent cannot get the value.
*/
export declare function useInputState<T>({ value, onChange, defaultValue, disabled }: UseInputStateProps<T>): UseInputStateResult<T>;
export {};