hooks-me
Version:
<div align="center"> <h1>hooks-me</h1> <div>React useful hooks.</div>
12 lines (11 loc) • 485 B
JavaScript
import { useCallback, useState } from "react";
var useValidatedState = function (initialValue, validator) {
var _a = useState(initialValue), value = _a[0], setValue = _a[1];
var _b = useState(validator(initialValue)), isValid = _b[0], setIsValid = _b[1];
var handleOnChange = useCallback(function (newValue) {
setValue(newValue);
setIsValid(validator(newValue));
}, []);
return [value, handleOnChange, isValid];
};
export default useValidatedState;