Function useClickOutside

  • 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

    const MyComponent = () => {
    const elementRef = useClickOutside(() => console.log("clicked"));

    return (
    <div ref={elementRef}>Foo</div>
    );
    };

    Type Parameters

    • InnerElement extends HTMLElement<InnerElement>

    Parameters

    Returns RefObject<InnerElement>

    a ref object you can attach to your node

Generated using TypeDoc