@mirawision/reactive-hooks
Version:
A comprehensive collection of 50+ React hooks for state management, UI interactions, device APIs, async operations, drag & drop, audio/speech, and more. Full TypeScript support with SSR safety.
27 lines (26 loc) • 757 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useInput = useInput;
const react_1 = require("react");
/**
* Hook that manages input field state
* Handles both string values and React change events
*
* @param initialValue - Initial input value
* @returns Tuple with current value and setter function
*/
function useInput(initialValue) {
const [value, setValue] = (0, react_1.useState)(initialValue);
const setValueWrapper = (input) => {
if (input === undefined) {
setValue('');
}
else if (typeof input === 'string') {
setValue(input);
}
else {
setValue(input.target.value);
}
};
return [value, setValueWrapper];
}