create useEventListener hook

This commit is contained in:
ghalestrilo 2020-08-13 17:27:38 -03:00
parent 99594a390c
commit 53a5198e02

View file

@ -52,3 +52,8 @@ export const useEffectWithComparison = (fn, props) => {
update(props); update(props);
}, Object.values(props)); }, Object.values(props));
}; };
export const useEventListener = (event, callback, useCapture = false) => useEffect(() => {
document.addEventListener(event, callback, useCapture);
return document.removeEventListener(event, callback, useCapture);
}, []);