Hooks for use with `validator.tool`.
npm install @validator.tool/hook@validator.tool/hook
===




Hooks for use with validator.tool.
``bash`
$ npm install @validator.tool/hook --save

`jsx
import { useEffect, useState, Fragment } from 'react';
import { useValidator } from '@validator.tool/hook';
export default function Demo() {
const [data, setData] = useState({
email: 'kennyiseeyou@gmail.com'
});
const { validator, handleReset, handleSubmit } = useValidator({
initValues: data,
});
const onSubmit = (value) => {
console.log('value', value)
}
const onReset = (value) => {
setData({ ...value });
}
function handleChange(env) {
const target = env.target;
const value = target.type === "checkbox" ? target.checked : target.value;
const name = target.name;
setData({ ...data, [name]: value });
}
return (
The ${val} must be a valid email address. : ''API
`ts
import Validator, { ValidatorOption, Values } from 'validator.tool';
export * from 'validator.tool';
export interface UseValidator extends ValidatorOption {}
export declare function useValidator(props?: UseValidator): {
validator: Validator;
forceUpdate: () => void;
/* Only Form Support /
handleSubmit: (handle?: ((value: Values, valid: boolean) => void) | undefined) => (evn: React.FormEvent) => void;
/* Only Form Support /
handleReset: (handle?: ((value: Values) => void) | undefined) => (evn: React.FormEvent) => void;
};
``- validator.tool Lightweight JavaScript form validation, that had minimal configuration and felt natural to use.
Licensed under the MIT License.