My idea was when user types the email in the input box when stops for 500 milliseconds that time only useEffects side effect will run other wise user continusly types side effects will not run that will clear with help of cleanUp function. side effects runs frist time when the app starts. After that any dependency changed cleanup function runs therafter side effects runs. so if i create setTimeout function in the side effects with 500 milliseconds and I clear the timeout function in the cleanup function it will clear the side effect. But when user stops typing in the input box in that time also dependency changed clenup function need to clear the side effects. But cleanup function runs properly but not clear the side effects side effects also runs how it possible? why cleanup function not clear the side effects in the user stop typing
useEffect(() => {
const timeoutHandler = setTimeout(() => {
setFormIsValid(
enteredEmail.includes("@") && enteredPassword.trim().length > 6
);
console.log("side effect");
}, 500);
return () => {
clearTimeout(timeoutHandler);
console.log("cleanUp function");
};
}, [enteredEmail, enteredPassword]);