diff --git a/components/lib/hooks/useEventListener.js b/components/lib/hooks/useEventListener.js index e260295416..5566f10dee 100644 --- a/components/lib/hooks/useEventListener.js +++ b/components/lib/hooks/useEventListener.js @@ -7,7 +7,6 @@ import { useUnmountEffect } from './useUnmountEffect'; export const useEventListener = ({ target = 'document', type, listener, options, when = true }) => { const targetRef = React.useRef(null); const listenerRef = React.useRef(null); - const prevListener = usePrevious(listener); const prevOptions = usePrevious(options); const bind = (bindOptions = {}) => { @@ -39,12 +38,11 @@ export const useEventListener = ({ target = 'document', type, listener, options, }, [target, when]); React.useEffect(() => { - // to properly compare functions we can implicitly converting the function to it's body's text as a String - if (listenerRef.current && ('' + prevListener !== '' + listener || prevOptions !== options)) { + if (listenerRef.current && (listenerRef.current !== listener || prevOptions !== options)) { unbind(); when && bind(); } - }, [listener, options, when]); + }, [listener, options]); useUnmountEffect(() => { unbind();