I'm getting a syntax error in when using React Hooks. Basically, I'm using an If statement inside useEffect and getting and Unexpected token error.
const [linkAnimation, setLinkAnimation] = useState();
const [isHovered, setIsHovered] = useState(true);
useEffect(() => {
setLinkAnimation(
if(isHovered === true){ //getting unexpected token on this line
console.log('true')
}
);
}, []);
Syntax seems straight forward, but looks like I'm missing something.
See codepen
setLinkAnimationis a function, and you are passing aif statementas an argument to the function. Error is expected.