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
*/
import { useCallback, useContext } from 'react';
import { useCallback, useContext, useMemo } from 'react';
import { SettingsContext } from '../settings-context';
import type {
WebSearchConfig,
@@ -131,27 +131,52 @@ export function useSettingsActions() {
[dispatch]
);
return {
setWebSearchConfig,
setWebSearchStatus,
setWebSearchLoading,
setWebSearchStatusLoading,
setWebSearchSaving,
setWebSearchError,
setWebSearchSuccess,
setGlobalEnvConfig,
setGlobalEnvLoading,
setGlobalEnvSaving,
setGlobalEnvError,
setGlobalEnvSuccess,
setProxyConfig,
setProxyLoading,
setProxySaving,
setProxyError,
setProxySuccess,
setProxyTestResult,
setProxyTesting,
setRawConfig,
setRawConfigLoading,
};
return useMemo(
() => ({
setWebSearchConfig,
setWebSearchStatus,
setWebSearchLoading,
setWebSearchStatusLoading,
setWebSearchSaving,
setWebSearchError,
setWebSearchSuccess,
setGlobalEnvConfig,
setGlobalEnvLoading,
setGlobalEnvSaving,
setGlobalEnvError,
setGlobalEnvSuccess,
setProxyConfig,
setProxyLoading,
setProxySaving,
setProxyError,
setProxySuccess,
setProxyTestResult,
setProxyTesting,
setRawConfig,
setRawConfigLoading,
}),
[
setWebSearchConfig,
setWebSearchStatus,
setWebSearchLoading,
setWebSearchStatusLoading,
setWebSearchSaving,
setWebSearchError,
setWebSearchSuccess,
setGlobalEnvConfig,
setGlobalEnvLoading,
setGlobalEnvSaving,
setGlobalEnvError,
setGlobalEnvSuccess,
setProxyConfig,
setProxyLoading,
setProxySaving,
setProxyError,
setProxySuccess,
setProxyTestResult,
setProxyTesting,
setRawConfig,
setRawConfigLoading,
]
);
}