UI & Dom
useClickOutside
Listen to click events outside the target element
- Import
- import { useClickOutside } from '@kubed/hooks;'
- Source
- View source code
- Docs
- Edit this page
- npm
- @kubed/hooks
Usage
useClickOutside Please click the button or outside the button to see the effect
API
The useClickOutside hook accepts three parameters:
handler
– the callback function that triggers the eventevents
– the event type used for monitoring, default value:['mousedown', 'touchstart']
nodes
– DOM nodes or Ref, supports arrays
1function useClickOutside<T extends HTMLElement = any>(2handler: () => void, events?: string[] | null, nodes?: HTMLElement[]3): React.MutableRefObject<T>
Params
Parameters | Default Value | Type | Description |
---|---|---|---|
handler | - | () => void | callback function that triggers the event |
events | ['mousedown', 'touchstart'] | (string[] null) | Event type for listening |
nodes | - | HTMLElement[] | DOM node or Ref, supports array |
Result
Parameters | Default Value | Type | Description |
---|---|---|---|
ref | - | React.MutableRefObject<T> | target element |