I'm trying to write an SPA with a React frontend, and the very minimal code I've written is complaining about an invalid hook call.
I understand that there are, per the error message, three major reasons for this error:
- 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 checked npm ls react
and npm ls react-dom
and they both report a single install of the respective package, with version 16.13.1, so I don't think it's reason #1 or reason #3. As for a rules-of-hooks violation, that doesn't seem possible given the code is just this:
import { useState } from "react";
import ReactDOM from "react-dom";
const Main = () => {
const [count, setCount] = useState(0);
return(
<>
</>
);
};
const reactRoot = document.getElementById("react-root");
ReactDOM.render(Main(), reactRoot);
That looks like a perfectly good functional component to me, and there are clearly no loops or conditionals. What else might be going on here?