I don't know why I'm receiving this error after running a test.
Invalid hook call. Hooks can only be called inside of the body of a function component.
This is how my code looks like
23 |
24 | const LandingPageNew = () => {
> 25 | const [displayElement, setDisplayedElement] = useState(1);
| ^
26 |
27 | const classes = useStyles();
28 | function manageIndicatorColors(element, number) {
How you can see I'm using hooks inside function components.
Do you have any ideas why this error is occurring?
I've only one React in my project
$ npm ls react
root@ C:\Users\szyma\Desktop\MVPs\pyramid_questionnaire_2
-- client@1.0.0 ->
C:\Users\szyma\Desktop\MVPs\pyramid_questionnaire_2\packages\client
-- react@17.0.1
Edit------------
It's pretty simple. LandingPageNew
is imported to App.js
import LandingPageNew from "./react/LandingPageNew";
And then
function App() {
return (
<Router>
<div className='appComponent'>
{/* <img src={background} className='top-background' /> */}
<Route path='/' exact component={LandingPageNew} />
<Route path='/create-account' component={CreateAccountPage} />
<Route path='/questionnaire' component={LandingPageNew} />
</div>
</Router>
);
}
export default App;
After using it inside App.js
everything is by "default"