DEV Community

Discussion on: How to (really) remove eventListeners in React

Collapse
 
stigkj profile image
Stig KleppeJørgensen

Even better: put the onKeyDown function inside React.useEffect. Then useCallback is not needed.

As Kent C Dodds suggests: "If you must define a function for your effect to call, then do it inside the effect callback, not outside." For more info see "Needlessly externally defined functions" on epicreact.dev/myths-about-useeffect

And it is also mentioned in the React docs: reactjs.org/docs/hooks-faq.html#is...

Collapse
 
anjantalatam profile image
Anjan Talatam

thanks for mentioning

Collapse
 
jamesfthomas profile image
James F. Thomas

I was thinking the same thing reading this article glad you commented it.