Skip to content

Commit 3cc2f50

Browse files
committed
fix: trigger only when changed
1 parent 10ca51d commit 3cc2f50

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/hooks/useHeights.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export default function useHeights<T>(
3333
cancelRaf();
3434

3535
const doCollect = () => {
36+
let changed = false;
37+
3638
instanceRef.current.forEach((element, key) => {
3739
if (element && element.offsetParent) {
3840
const htmlElement = findDOMNode<HTMLElement>(element);
@@ -45,12 +47,15 @@ export default function useHeights<T>(
4547

4648
if (heightsRef.current.get(key) !== totalHeight) {
4749
heightsRef.current.set(key, totalHeight);
50+
changed = true;
4851
}
4952
}
5053
});
5154

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

5661
if (sync) {

0 commit comments

Comments
 (0)