forked from github/plane
22 lines
430 B
TypeScript
22 lines
430 B
TypeScript
|
"use client";
|
||
|
|
||
|
import { useEffect } from "react";
|
||
|
|
||
|
const useOutSideClick = (ref: any, callback: any) => {
|
||
|
const handleClick = (e: any) => {
|
||
|
if (ref.current && !ref.current.contains(e.target)) {
|
||
|
callback();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
useEffect(() => {
|
||
|
document.addEventListener("click", handleClick);
|
||
|
|
||
|
return () => {
|
||
|
document.removeEventListener("click", handleClick);
|
||
|
};
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export default useOutSideClick;
|