Skip to content

Commit eaadc23

Browse files
fix: reset showgraph state when unmounting button
1 parent 96e0c00 commit eaadc23

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

web/src/components/MetricsPage.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ export const ToggleGraph: React.FC = () => {
326326

327327
const dispatch = useDispatch();
328328
const toggle = React.useCallback(() => dispatch(toggleGraphs()), [dispatch]);
329+
// Use an empty useEffect to get access to the cleanup function so that if graphs are
330+
// currently hidden then we toggle one more time as we unmount
331+
React.useEffect(
332+
() => () => {
333+
if (hideGraphs) {
334+
toggle();
335+
}
336+
},
337+
// eslint-disable-next-line react-hooks/exhaustive-deps
338+
[hideGraphs],
339+
);
329340

330341
const icon = hideGraphs ? <ChartLineIcon /> : <CompressIcon />;
331342

0 commit comments

Comments
 (0)