fix(settings): memoize useSettingsActions to prevent infinite render loop

- wrap return object in useMemo with all action callbacks as deps

- prevents new object reference on every render

- fixes Maximum update depth exceeded error on settings page
This commit is contained in:
kaitranntt
2025-12-21 04:09:13 -05:00
parent b8b9101466
commit 4f75e105a9
+49 -24
View File
@@ -3,7 +3,7 @@
* Hooks for accessing and updating settings context state * Hooks for accessing and updating settings context state
*/ */
import { useCallback, useContext } from 'react'; import { useCallback, useContext, useMemo } from 'react';
import { SettingsContext } from '../settings-context'; import { SettingsContext } from '../settings-context';
import type { import type {
WebSearchConfig, WebSearchConfig,
@@ -131,27 +131,52 @@ export function useSettingsActions() {
[dispatch] [dispatch]
); );
return { return useMemo(
setWebSearchConfig, () => ({
setWebSearchStatus, setWebSearchConfig,
setWebSearchLoading, setWebSearchStatus,
setWebSearchStatusLoading, setWebSearchLoading,
setWebSearchSaving, setWebSearchStatusLoading,
setWebSearchError, setWebSearchSaving,
setWebSearchSuccess, setWebSearchError,
setGlobalEnvConfig, setWebSearchSuccess,
setGlobalEnvLoading, setGlobalEnvConfig,
setGlobalEnvSaving, setGlobalEnvLoading,
setGlobalEnvError, setGlobalEnvSaving,
setGlobalEnvSuccess, setGlobalEnvError,
setProxyConfig, setGlobalEnvSuccess,
setProxyLoading, setProxyConfig,
setProxySaving, setProxyLoading,
setProxyError, setProxySaving,
setProxySuccess, setProxyError,
setProxyTestResult, setProxySuccess,
setProxyTesting, setProxyTestResult,
setRawConfig, setProxyTesting,
setRawConfigLoading, setRawConfig,
}; setRawConfigLoading,
}),
[
setWebSearchConfig,
setWebSearchStatus,
setWebSearchLoading,
setWebSearchStatusLoading,
setWebSearchSaving,
setWebSearchError,
setWebSearchSuccess,
setGlobalEnvConfig,
setGlobalEnvLoading,
setGlobalEnvSaving,
setGlobalEnvError,
setGlobalEnvSuccess,
setProxyConfig,
setProxyLoading,
setProxySaving,
setProxyError,
setProxySuccess,
setProxyTestResult,
setProxyTesting,
setRawConfig,
setRawConfigLoading,
]
);
} }