From cd871ec359884886f19aa30c176944cde5df1105 Mon Sep 17 00:00:00 2001 From: vitorRibeiro7 Date: Fri, 17 Jan 2025 12:25:35 -0300 Subject: [PATCH] refactor: add non re-render rules to useEffect --- .../pages/game-details/sidebar-section/sidebar-section.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/pages/game-details/sidebar-section/sidebar-section.tsx b/src/renderer/src/pages/game-details/sidebar-section/sidebar-section.tsx index 4b01adeb..e24f677b 100644 --- a/src/renderer/src/pages/game-details/sidebar-section/sidebar-section.tsx +++ b/src/renderer/src/pages/game-details/sidebar-section/sidebar-section.tsx @@ -14,10 +14,12 @@ export function SidebarSection({ title, children }: SidebarSectionProps) { const [height, setHeight] = useState(0); useEffect(() => { - if (content.current) { + if (content.current && content.current.scrollHeight !== height) { setHeight(isOpen ? content.current.scrollHeight : 0); + } else if (!isOpen) { + setHeight(0); } - }, [isOpen, children]); + }, [isOpen, children, height]); return (