refactor: add non re-render rules to useEffect

This commit is contained in:
vitorRibeiro7 2025-01-17 12:25:35 -03:00
parent 548b7c3f41
commit cd871ec359

View File

@ -14,10 +14,12 @@ export function SidebarSection({ title, children }: SidebarSectionProps) {
const [height, setHeight] = useState(0); const [height, setHeight] = useState(0);
useEffect(() => { useEffect(() => {
if (content.current) { if (content.current && content.current.scrollHeight !== height) {
setHeight(isOpen ? content.current.scrollHeight : 0); setHeight(isOpen ? content.current.scrollHeight : 0);
} else if (!isOpen) {
setHeight(0);
} }
}, [isOpen, children]); }, [isOpen, children, height]);
return ( return (
<div> <div>