From 53a5198e02c4f0894922a17f8e4635d04662196a Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Thu, 13 Aug 2020 17:27:38 -0300 Subject: [PATCH] :sparkles: create useEventListener hook --- client/utils/custom-hooks.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/utils/custom-hooks.js b/client/utils/custom-hooks.js index d88066a5..cf6c0130 100644 --- a/client/utils/custom-hooks.js +++ b/client/utils/custom-hooks.js @@ -52,3 +52,8 @@ export const useEffectWithComparison = (fn, props) => { update(props); }, Object.values(props)); }; + +export const useEventListener = (event, callback, useCapture = false) => useEffect(() => { + document.addEventListener(event, callback, useCapture); + return document.removeEventListener(event, callback, useCapture); +}, []);