bobangajicsm/react-portfolio-website

useEffect error

Closed this issue · 3 comments

86 Warning: useEffect must not return anything besides a function, which is used for clean-up. You returned: 18

I am getting this error when I implemented the useEffect function to animate the letters.

errors12
code1
s

how did you resolve the useEffect error?

how did you resolve the useEffect error?

so we shouldn't use useEffect inside the home function (in this case). We shouldn't include any superstates insde the main function.

how did you resolve the useEffect error?

it can also be resolved using a cleanup function, like this

useEffect(() => {
const timeoutId = setTimeout(() => {
setLetterClass('text-animate-hover');
}, 4000);

// Cleanup function to clear the timeout if the component unmounts or the effect is re-triggered
return () => {
clearTimeout(timeoutId);
};
}, []);