shivamsouravjha / Let-us-travel

A MERN app to let users share their experience of places along with Details.
2 stars 2 forks source link

useState not working #2

Closed shivamsouravjha closed 3 years ago

shivamsouravjha commented 3 years ago

./src/shared/Components/Navigation/mainnavigation.js Line 10:44: React Hook "useState" is called in function "mainnavigation" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks

Search for the keywords to learn more about each error.

after NPM install,this error appears, this was used in sidedrawer to make navigation bar in phone appear upon click.

Ohranj commented 3 years ago

You need to capitalize the component name "MainNavigation" and it's export

shivamsouravjha commented 3 years ago

Any Specific reason? I thought it's a way of writing not some mandatory way.

Ohranj commented 3 years ago

Any Specific reason? I thought it's a way of writing not some mandatory way.

It's mandatory for your own components as the code gets passed to React.createElement() before render.

React will treat lowercase component names as jsx and so try and render it as if it was an HTML element such as a div or p tag. Just changing it to starting with a capital letter tells react this is a react component and so it will allow you to access reacts own lifecycle methods inside.

shivamsouravjha commented 3 years ago

yup, that the case, but had to edit the header as well. thanks!