Skip to content

Commit

Permalink
fix: trigger only when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jan 16, 2025
1 parent 10ca51d commit 3cc2f50
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hooks/useHeights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default function useHeights<T>(
cancelRaf();

const doCollect = () => {
let changed = false;

instanceRef.current.forEach((element, key) => {
if (element && element.offsetParent) {
const htmlElement = findDOMNode<HTMLElement>(element);
Expand All @@ -45,12 +47,15 @@ export default function useHeights<T>(

if (heightsRef.current.get(key) !== totalHeight) {
heightsRef.current.set(key, totalHeight);
changed = true;
}
}
});

// Always trigger update mark to tell parent that should re-calculate heights when resized
setUpdatedMark((c) => c + 1);
if (changed) {
setUpdatedMark((c) => c + 1);
}
};

if (sync) {
Expand Down

0 comments on commit 3cc2f50

Please sign in to comment.