Register a callback on click events outside of a dom node. Can be contained to a certain part of the page by passing a ref to the node that counts as the outer limit. Defaults to window.
const MyComponent = () => { const elementRef = useClickOutside(() => console.log("clicked")); return ( <div ref={elementRef}>Foo</div> );}; Copy
const MyComponent = () => { const elementRef = useClickOutside(() => console.log("clicked")); return ( <div ref={elementRef}>Foo</div> );};
function to be called when the user clicked outside of the target
UseClickOutsideOptions
a ref object you can attach to your node
Generated using TypeDoc
Register a callback on click events outside of a dom node. Can be contained to a certain part of the page by passing a ref to the node that counts as the outer limit. Defaults to window.
Example