Как я могу указать тип TypeScript для событий mousedown
и touchstart
?
function useOnClickOutside(ref: React.RefObject<any>, handler: () => void) {
React.useEffect(() => {
const listener = (event: React.TouchEvent | React.MouseEvent) => {
if (!ref || !ref.current) {
return;
}
const elem = document.getElementsByClassName(uniqueClassName)[0];
if (elem.contains(event.target)) {
return;
}
handler();
};
document.addEventListener("mousedown", listener);
document.addEventListener("touchstart", listener);
return () => {
document.removeEventListener("mousedown", listener);
document.removeEventListener("touchstart", listener);
};
}, [ref, handler]);
}