usehooks
usehooks copied to clipboard
useMedia dependency array and ES lint warning
I'm working on a project that uses the useMedia hook and currently it looks like another developer has added dependencies to the useEffect to satisfy eslint:
[getValue, mediaQueryLists] // Empty array ensures effect is only run on mount and unmount
While investigating an issue, I discovered that simply removing the the dependencies and using an empty array [], the issue goes away - it probably explains why the original hook was written this way in the first place!
Having said that, I've been asked to see if it's possible to satisfy the linter AND make the issue go away so was hoping someone could help, or provide an explanation to a less experienced developer as to why the dependency array has to be left as is for this hook to work properly.
Thanks!