DEV Community

Discussion on: Handle keyboard event with React Hooks

Collapse
 
nkzn profile image
Yukiya Nakagawa • Edited

Sung and e1cb4's answer has explained all my opinion 👏

these are purpose:

  • avoiding memory leak
  • each component should clean up each its own event handling

the function at return statement is called when the component is unmounted, so event handler is keeped active during the component is being mounted.