got "invalid hook call" when writing function component with arrow function.
I tried to use hooks in functional component just like below.
// this will get error
const Foo = () => {
const fooRef = useRef(null);
useEffect(() => {
console.log(fooRef.current);
}, [])
return (
<h1>this is foo</h1>
);
}
export default Foo;
but got error message like below.
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app
I have been check 1~3, but still got error.