werkbank
    Preparing search index...

    Function useOutsideClick

    • Detects clicks outside of a specified element.

      Type Parameters

      • T extends HTMLElement = HTMLElement

        The HTML element type.

      Parameters

      • cb: Callback

        The callback to execute when an outside click occurs.

      Returns RefObject<T | null>

      A ref object to attach to the target element.

      This hook returns a ref to attach to the element you want to monitor. It subscribes to global pointer down events and checks if the click target is outside the ref element.

      const ref = useOutsideClick(() => {
      closeModal();
      });
      return <div ref={ref}>Modal Content</div>;