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 event
  • events – the event type used for monitoring, default value: ['mousedown', 'touchstart']
  • nodes – DOM nodes or Ref, supports arrays
1
function useClickOutside<T extends HTMLElement = any>(
2
handler: () => void, events?: string[] | null, nodes?: HTMLElement[]
3
): React.MutableRefObject<T>

Params

ParametersDefault ValueTypeDescription
handler-() => voidcallback function that triggers the event
events['mousedown', 'touchstart'](string[] null)Event type for listening
nodes-HTMLElement[]DOM node or Ref, supports array

Result

ParametersDefault ValueTypeDescription
ref-React.MutableRefObject<T>target element