[BUG] useEffect has a missing dependency
gbowne1 opened this issue · 2 comments
After the recent merges and features, I am now getting this warning/error:
[eslint]
src/pages/Home/Home.jsx
Line 58:8: React Hook useEffect has a missing dependency: 'location.state.loggin'. Either include it or remove the dependency array react-hooks/exhaustive-deps
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
WARNING in [eslint]
src/pages/Home/Home.jsx
Line 58:8: React Hook useEffect has a missing dependency: 'location.state.loggin'. Either include it or remove the dependency array react-hooks/exhaustive-deps
webpack compiled with 1 warning
I thought this may be because login is misspelled loggin
, but even with correcting the spelling still has a missing dep warning.
I am also getting location.state is null from the 'Home.jsx` component.
I am assuming it is because the useEffect in Home.jsx is missing the location.state in the brackets like [location.state].
in that case I would think this might work:
useEffect(() => {
if (
location.state &&
location.state.login &&
localStorage.getItem('user')
) {
notify(JSON.parse(localStorage.getItem('user')).username);
}
}, [location.state]);
I have fixed this in my latest Pull Request for profile page