Pacote
    Preparing search index...
    • Returns a ref for an element and calls a handler when selected document events occur outside that element.

      Type Parameters

      • E extends HTMLElement

      Parameters

      • type: (keyof DocumentEventMap) | (keyof DocumentEventMap)[]

        One or more document event names to observe.

      • handler: EventListener

        Listener called for events whose target is outside the element.

      Returns RefObject<E | null>

      A ref to attach to the element treated as inside.

      import { useOutside } from '@pacote/react-use-outside'

      function Modal({ onClose }: { onClose: () => void }) {
      const ref = useOutside<HTMLDivElement>('click', () => {
      console.log('Clicked outside')
      onClose()
      })

      return <div ref={ref}>Click outside this element</div>
      }