UNPKG

@appbuckets/react-ui

Version:
40 lines (37 loc) 956 B
import { __read } from 'tslib'; import * as React from 'react'; /** * Use this hook to get automatically the numeric input value * and the handler function to attach to numeric input. * Additionally function to force change will be returned * * @param initialValue */ function useNumericInputValue(initialValue) { // ---- // Internal State // ---- var _a = __read( React.useState( initialValue !== null && initialValue !== void 0 ? initialValue : null ), 2 ), numericInputValue = _a[0], setNumericInputValue = _a[1]; // ---- // Handler // ---- var handleInputChange = React.useCallback(function (e, props) { var _a; /** Set new value */ setNumericInputValue( (_a = props.value) !== null && _a !== void 0 ? _a : null ); }, []); // ---- // Hook Return // ---- return [numericInputValue, handleInputChange, setNumericInputValue]; } export { useNumericInputValue };