useClickOutside
Detects click and touch events outside from a specific element.
Installation
Install the custom hook from your command line.
npm i @raddix/use-click-outside
Usage
Basic example
In this example, when the user clicks outside the modal it will close.
API
Parameters
Name | Description | Required | Type |
---|---|---|---|
ref | DOM element being referenced. | Yes | RefObject |
callback | This function is called whenever a click event is detected outside of the referenced element. | Yes | function |