@appbuckets/react-ui
Version:
Just Another React UI Framework
39 lines (36 loc) • 910 B
JavaScript
import { __read } from 'tslib';
import * as React from 'react';
/**
* Use this hook to get automatically the input value
* and the handler function to attach to input.
* Additionally function to force change will be returned
*
* @param initialValue
*/
function useInputValue(initialValue) {
// ----
// Internal State
// ----
var _a = __read(
React.useState(
initialValue !== null && initialValue !== void 0 ? initialValue : ''
),
2
),
inputValue = _a[0],
setInputValue = _a[1];
// ----
// Handler
// ----
var handleInputChange = React.useCallback(function (e, props) {
/** Get the value */
var value = props.value;
/** Set new value */
setInputValue(value !== null && value !== void 0 ? value : '');
}, []);
// ----
// Hook Return
// ----
return [inputValue, handleInputChange, setInputValue];
}
export { useInputValue };