EN
React - how to fix "React Hook useEffect has a missing dependency" warning?
1
answers
0
points
I am using useEffect() hook with empty array of dependencies ([]) as a second argument, and I keep getting the following warning:
React Hook useEffect has a missing dependency: 'date'. Either include it or remove the dependency array
However, the useEffect() in my code needs the empty dependency array in order to execute code on component mount.
How can I get rid of this warning?
1 answer
0
points
The warning you get comes from ESLint, a tool to control code quality.
You can disable ESLint for the next line using the following comment in your code:
// eslint-disable-next-line
Place the comment before the line that you want to ignore, so you won't get any warnings.
In your case that would be at the end of useEffect arrow function:
useEffect(() => {
// useEffect function body here...
// eslint-disable-next-line
}, []);
References
0 comments
Add comment