Skip to content

Commit 615b5e0

Browse files
committed
fix(Popup): prevent popup rerender
1 parent 41cbbe6 commit 615b5e0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/Popup/Popup.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ const Popup: FC<PropsWithChildren<PopupProps>> = ({
4444
};
4545

4646
const updatePopupPosition = useCallback(() => {
47-
setPopupPosition(getPopupPosition());
47+
const newPosition = getPopupPosition();
48+
setPopupPosition((prevPosition) => {
49+
if (
50+
prevPosition.left !== newPosition.left ||
51+
prevPosition.top !== newPosition.top ||
52+
prevPosition.transform !== newPosition.transform
53+
) {
54+
return newPosition;
55+
}
56+
return prevPosition;
57+
});
4858
}, [getPopupPosition]);
4959

5060
useResize(updatePopupPosition);
@@ -73,6 +83,7 @@ const Popup: FC<PropsWithChildren<PopupProps>> = ({
7383
}, [targetRef, updatePopupPosition]);
7484

7585
if (!targetRef) return null;
86+
7687
if (!portal) return null;
7788

7889
return createPortal(

0 commit comments

Comments
 (0)