umami/hooks/useDocumentClick.js

14 lines
273 B
JavaScript
Raw Normal View History

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