We can capture the pattern we created with useCallback
into our own useListener
hook. This is essentially copying and pasting the code we wrote, but being very aware of the "dependencies" that useCallback
requires so that it doesn't destroy our listener each time React renders.