umami/hooks/useDocumentClick.js
2020-08-05 23:03:07 -07:00

14 lines
273 B
JavaScript

import { useEffect } from 'react';
export default function useDocumentClick(handler) {
useEffect(() => {
document.addEventListener('click', handler);
return () => {
document.removeEventListener('click', handler);
};
}, [handler]);
return null;
}