From 2f1d1c56d30fae92bee5a5c672fc4afd03eaf742 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Sat, 25 Nov 2023 21:20:32 +0000 Subject: [PATCH] Fixed #4656 - DataTable: memory leak when data updated continuously --- components/lib/hooks/useEventListener.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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();