@sooni-hooks/use-input
Version:
React Hook to use input easy way
24 lines (21 loc) • 474 B
JavaScript
import { useState } from "react";
const useInput = (init, verification) => {
const [value, setValue] = useState(init);
const onChange = (event) => {
const {
target: { value },
} = event;
let willUpdate = true;
if (typeof verification === "function") {
willUpdate = verification(value);
}
if (willUpdate) {
setValue(value);
}
};
return {
value,
onChange,
};
};
export default useInput;