umami/hooks/useDocumentClick.js

16 lines
299 B
JavaScript
Raw Normal View History

2020-08-06 08:03:07 +02:00
import { useEffect } from 'react';
2023-05-18 08:20:06 +02:00
export function useDocumentClick(handler) {
2020-08-06 08:03:07 +02:00
useEffect(() => {
document.addEventListener('click', handler);
return () => {
document.removeEventListener('click', handler);
};
}, [handler]);
return null;
}
2023-05-18 08:20:06 +02:00
export default useDocumentClick;