diff --git a/src/components/utils/useOutsideClick/useOutsideClick.tsx b/src/components/utils/useOutsideClick/useOutsideClick.tsx index 7e22ceb0bb..0c54c8afbf 100644 --- a/src/components/utils/useOutsideClick/useOutsideClick.tsx +++ b/src/components/utils/useOutsideClick/useOutsideClick.tsx @@ -17,24 +17,20 @@ type UseOutsideClickType = (props: UseOutsideClickProps { React.useEffect(() => { - if (ref) { - const callback = (e: MouseEvent | TouchEvent) => { - const elem = ref?.current; + const callback = (e: MouseEvent | TouchEvent) => { + const elem = ref?.current; - if (elem && !elem.contains(e.target as Node) && handler) { - handler(); - } - }; + if (elem && !elem.contains(e.target as Node) && handler) { + handler(); + } + }; - window.addEventListener('click', callback, {capture: true}); - window.addEventListener('touchstart', callback, {capture: true}); + window.addEventListener('click', callback, {capture: true}); + window.addEventListener('touchstart', callback, {capture: true}); - return () => { - window.removeEventListener('click', callback, {capture: true}); - window.removeEventListener('touchstart', callback, {capture: true}); - }; - } - - return undefined; + return () => { + window.removeEventListener('click', callback, {capture: true}); + window.removeEventListener('touchstart', callback, {capture: true}); + }; }, [handler, ref]); };