@light-sheet/react
Version:
FortuneSheet is a drop-in javascript spreadsheet library that provides rich features like Excel and Google Sheets
15 lines • 510 B
JavaScript
import { useEffect } from "react";
export function useOutsideClick(containerRef, handler, deps) {
useEffect(function () {
function handleClickOutside(e) {
if (containerRef.current && !containerRef.current.contains(e.target)) {
handler();
}
}
document.addEventListener("mousedown", handleClickOutside);
return function () {
document.removeEventListener("mousedown", handleClickOutside);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}