Event Handler
Event handlers can be used to handle and verify user input, user actions, and browser actions.
Last updated
Was this helpful?
Event handlers can be used to handle and verify user input, user actions, and browser actions.
Last updated
Was this helpful?
Basically, what this hook does is that, it takes a parameter with value true or false and toggles that value to opposite. It's useful when we want to take some action into it's opposite action, for example: show and hide modal, show more/show less text, open/close side menu.
If you find yourself adding a lot of event listeners using useEffect
you might consider moving that logic to a custom hook. In the recipe below we create a useEventListener
hook that handles checking if addEventListener
is supported, adding the event listener, and removal on cleanup.