How to solve React Hook useEffect has a missing dependency: func Either include it or remove the dependency array

 

Issue : 

I got this issue on typescript when using hook component function from react

React Hook useEffect has a missing dependency: 'getData'. Either include it or remove the dependency array 

Solution :

Now I found the solution.. it simple because it happened only when we use typescript

put this comment above end of function like this

// eslint-disable-next-line react-hooks/exhaustive-deps

become like this 


This comment line aims to ignore the errors in the next line of code


useEffect(() => {
        getData();
   // eslint-disable-next-line react-hooks/exhaustive-deps
}, [location]);

and your problem should be gone 

thanks hope it help, sorry for bad english

Comments