DEV Community

George Bardi
George Bardi

Posted on • Updated on

⚛️ useClickAway, react hook that reacts to clicks outside the element

React hook useClickAway() that reacts to clicks outside the bound element, and calls the expression that is passed in when this event is detected.

Suppose you're working on a Modal component that renders a dialog box, and you wish to close the modal if the user clicks away this is the ideal scenario for useClickAway custom hook.

Github link: https://github.com/geobde/use-click-away
Npm Link: https://www.npmjs.com/package/use-click-away

Top comments (0)