Skip to content

Commit

Permalink
changed breakdown charts memo to only re-render if the chart is open
Browse files Browse the repository at this point in the history
  • Loading branch information
mokelgit committed Nov 26, 2024
1 parent 648c9bb commit 796bac4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/layout/Economics/BreakdownCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -1164,3 +1169,4 @@ export default React.memo(BreakdownCharts, (prevProps, nextProps) => {
prevProps.isMonthly === nextProps.isMonthly
);
});

0 comments on commit 796bac4

Please sign in to comment.