From 796bac44c15c7b70721fc15b5ac2fc394e43a3f3 Mon Sep 17 00:00:00 2001 From: mokelgit Date: Tue, 26 Nov 2024 08:36:57 -0500 Subject: [PATCH] changed breakdown charts memo to only re-render if the chart is open --- components/layout/Economics/BreakdownCharts.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/layout/Economics/BreakdownCharts.tsx b/components/layout/Economics/BreakdownCharts.tsx index 92b97a4f..d9bcab0c 100644 --- a/components/layout/Economics/BreakdownCharts.tsx +++ b/components/layout/Economics/BreakdownCharts.tsx @@ -1153,7 +1153,12 @@ function BreakdownCharts({ } export default React.memo(BreakdownCharts, (prevProps, nextProps) => { - // Custom comparison function to prevent unnecessary re-renders + // Prevent re-renders if isOpen is false in both prev and next props + if (!prevProps.isOpen && !nextProps.isOpen) { + return true; // No need to re-render + } + + // Normal comparison logic return ( prevProps.data === nextProps.data && prevProps.dailyData === nextProps.dailyData && @@ -1164,3 +1169,4 @@ export default React.memo(BreakdownCharts, (prevProps, nextProps) => { prevProps.isMonthly === nextProps.isMonthly ); }); +