Skip to content

Commit

Permalink
Fixed #4656 - DataTable: memory leak when data updated continuously
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 25, 2023
1 parent 034afc2 commit 2f1d1c5
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions components/lib/hooks/useEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) => {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2f1d1c5

Please sign in to comment.