Got rid of unnecessary rerenders by memoizing the integrationstate function.

This commit is contained in:
Skorpios committed 2025-03-08 17:13:20 -08:00
1 parent 99ec5be865
commit d335cfb4ee
1 file changed
+5 -5
@@ -1,4 +1,4 @@
import { useState } from "react"; import { useState, useMemo } from "react";
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
@@ -86,8 +86,8 @@ const NotificationIntegrationModal = ({
const theme = useTheme(); const theme = useTheme();
const [tabValue, setTabValue] = useState(0); const [tabValue, setTabValue] = useState(0);
// Initialize integrations state based on available notification types // Memoized function to initialize integrations state
const initializeIntegrationsState = () => { const initialIntegrationsState = useMemo(() => {
const state = {}; const state = {};
notificationTypes.forEach(type => { notificationTypes.forEach(type => {
@@ -102,9 +102,9 @@ const NotificationIntegrationModal = ({
}); });
return state; return state;
}; }, [monitor, notificationTypes]); // Only recompute when these dependencies change
const [integrations, setIntegrations] = useState(initializeIntegrationsState()); const [integrations, setIntegrations] = useState(initialIntegrationsState);
const handleChangeTab = (event, newValue) => { const handleChangeTab = (event, newValue) => {
setTabValue(newValue); setTabValue(newValue);