mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
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;
|