Returns a ref for an element and calls a handler when selected document events occur outside that element.
One or more document event names to observe.
Listener called for events whose target is outside the element.
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>} Copy
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>}
Returns a ref for an element and calls a handler when selected document events occur outside that element.