This is part of my code in React js:
export default function Registration() {
const [email, setEmail] = useState(null);
const [password, setPassword] = useState(null);
const [passwordRepeat, setPasswordRepeat] = useState(null);
const [isFieldsOK, setFieldsOK] = useState(false);
useEffect(() => {
if (checkFieldsOK()) {
setFieldsOK(true);
} else {
setFieldsOK(false);
}
}, [checkFieldsOK])
const checkFieldsOK = () => {
return (isEmail(email) && isValidPassword(password) && passwordRepeat === password);
}
}
I have the isFieldsOK state which tells me if my fields are valid, and I want it to "listen" to every change in the Registration function. After running this, I get this warning:
The 'checkFieldsOK' function makes the dependencies of useEffect Hook (at line 34) change on every render. Move it inside the useEffect callback. Alternatively, wrap the definition of 'checkFieldsOK' in its own useCallback() Hook react-hooks/exhaustive-deps
What exactly wrong with my code? What should I change and why? Thank you!