DEV Community

Discussion on: My First Custom Hook in React

Collapse
 
jacobedawson profile image
Jacob E. Dawson • Edited

Hi Lori,

Nice post! I'm getting into hooks as well atm.

One question: is there a reason that you put 'isMobile' in the deps array of the useEffect hook? As far as I understand, if you add an empty array then useEffect will only run on mount & unmount, whereas in this case as the page is resized the boolean value of 'isMobile' will change and run useEffect again each time. It won't duplicate the event listener but seems unnecessary, unless I'm missing something?

Cheers,

Jake