From 91dcd06cf564650be0d4d8b06c64e7c0864704a1 Mon Sep 17 00:00:00 2001 From: Dendi Date: Mon, 22 Apr 2024 22:33:31 +0800 Subject: [PATCH] fix: fix dumplicate caculate --- src/content/drawer/index.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/content/drawer/index.tsx b/src/content/drawer/index.tsx index 4fc8daf..acb4489 100644 --- a/src/content/drawer/index.tsx +++ b/src/content/drawer/index.tsx @@ -44,19 +44,23 @@ export default function PersistentDrawerRight() { const handleResize = () => { // 当窗口大小变化时,更新 width 的值 - setDrawerWidth(caculateDrawerWidth()); - setBackWidth(caculateBackWidth()); + if (drawerWidth !== caculateDrawerWidth()) { + setDrawerWidth(caculateDrawerWidth()); + } + if (backWidth !== caculateBackWidth()) { + setBackWidth(caculateBackWidth()); + } }; // 动态更新width - // React.useEffect(() => { - // const timer = setInterval(() => { - // handleResize(); - // }, 1000); - // return () => { - // clearInterval(timer); - // }; - // }, []); + React.useEffect(() => { + const timer = setInterval(() => { + handleResize(); + }, 1000); + return () => { + clearInterval(timer); + }; + }, []); React.useEffect(() => { // 添加窗口大小变化时的事件监听器