✨ create useEventListener hook
This commit is contained in:
parent
99594a390c
commit
53a5198e02
1 changed files with 5 additions and 0 deletions
|
@ -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);
|
||||
}, []);
|
||||
|
|
Loading…
Reference in a new issue