const [errors, setErrors] = React.useState([]);
const [initErrors, setInitErrors] = React.useState([]);
const [password, setPassword] = React.useState("");
useEffect(() => {
async function validate(password) {
try {
const result = await passwordSchema.validate(
{
password
},
{ abortEarly: false }
);
if (!!result) {
setErrors([]);
}
} catch (e) {
setErrors(e.errors);
}
}
validate(password);
}, [password]);
useEffect(() => {
async function validate(password) {
try {
const result = await passwordSchema.validate(
{
password
},
{ abortEarly: false }
);
if (!!result) {
setErrors([]);
}
} catch (e) {
setInitErrors(e.errors);
}
}
validate(password);
}, []);