📅  最后修改于: 2022-03-11 14:55:32.599000             🧑  作者: Mango
const useOutsideAlerter = (ref: any) => {
useEffect(() => {
function handleClickOutside(event: any) {
if (ref.current && !ref.current.contains(event.target)) {
setOpen(0);
}
}
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, [ref]);
};
const wrapperRef = useRef(null);
useOutsideAlerter(wrapperRef);
suppose this div works as a popup and i want
to close this popup when clicking outside of the div