@premieroctet/next-admin
Version:
Next-Admin provides a customizable and turnkey admin dashboard for applications built with Next.js and powered by the Prisma ORM. It aims to simplify the development process by providing a turnkey admin system that can be easily integrated into your proje
19 lines (18 loc) • 590 B
JavaScript
import { useEffect, useRef } from "react";
const useClickOutside = (callback)=>{
const ref = useRef(null);
useEffect(()=>{
const handleClickOutside = (event)=>{
if (ref.current && !ref.current.contains(event.target)) callback();
};
document.addEventListener("mousedown", handleClickOutside);
return ()=>{
document.removeEventListener("mousedown", handleClickOutside);
};
}, [
callback
]);
return ref;
};
const useCloseOnOutsideClick = useClickOutside;
export { useCloseOnOutsideClick as default };