Skip to content

Commit

Permalink
Clear debounce during cleanup useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrucs committed Oct 15, 2024
1 parent a12d59d commit 74898ec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/Map/SearchMap/MoveHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const MoveHandler: React.FC<Props> = ({ onMove }) => {
map.on('moveend', handleMove);
return () => {
map.off('moveend', handleMove);
handleMove.clear();
};
}, [handleMove, map]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const useDetailsCard = (hasMedia = false) => {
debouncedResize();
global.addEventListener('resize', handleResize);
return () => {
debouncedResize.clear();
global.removeEventListener('resize', handleResize);
};
}, [debouncedResize]);
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/hooks/useSectionsReferences.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useRef, useState } from 'react';
import { useCallback, useMemo, useRef, useState } from 'react';
import { DetailsSections, DetailsSectionsPosition } from 'components/pages/details/useDetails';
import debounce from 'debounce';
import { getDimensions } from 'components/pages/details/utils';
Expand All @@ -22,7 +22,7 @@ const useSectionsReferences = () => {
[sectionName],
);

const handleResize = useCallback(
const handleResize = useMemo(
() =>
debounce(
() => {
Expand All @@ -49,6 +49,7 @@ const useSectionsReferences = () => {
global.addEventListener('resize', handleResize);
global.addEventListener('scroll', handleResize);
return () => {
handleResize.clear();
global.removeEventListener('resize', handleResize);
global.removeEventListener('scroll', handleResize);
};
Expand Down

0 comments on commit 74898ec

Please sign in to comment.