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
Even better: put the
onKeyDown
function insideReact.useEffect
. ThenuseCallback
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...
thanks for mentioning
I was thinking the same thing reading this article glad you commented it.