struct-ui-components
Version:
A collection of reusable, customizable React components built with TypeScript, Tailwind CSS, and Storybook. Designed for modern UI development with flexibility and scalability.
17 lines (15 loc) • 390 B
text/typescript
import type { RefObject } from "react";
import { useEventListener } from "../";
export const useClickOutside = (
ref: RefObject<HTMLElement>,
cb: (event: MouseEvent | Event) => void,
): void => {
useEventListener(
"click",
(e: MouseEvent | Event) => {
if (ref.current == null || ref.current.contains(e.target as Node)) return;
cb(e);
},
document,
);
};