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 committed 2025-12-21 04:09:13 -05:00
1 parent b8b9101466
commit 4f75e105a9
1 file changed
+28 -3
+28 -3
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,7 +131,8 @@ export function useSettingsActions() {
[dispatch] [dispatch]
); );
return { return useMemo(
() => ({
setWebSearchConfig, setWebSearchConfig,
setWebSearchStatus, setWebSearchStatus,
setWebSearchLoading, setWebSearchLoading,
@@ -153,5 +154,29 @@ export function useSettingsActions() {
setProxyTesting, setProxyTesting,
setRawConfig, setRawConfig,
setRawConfigLoading, setRawConfigLoading,
}; }),
[
setWebSearchConfig,
setWebSearchStatus,
setWebSearchLoading,
setWebSearchStatusLoading,
setWebSearchSaving,
setWebSearchError,
setWebSearchSuccess,
setGlobalEnvConfig,
setGlobalEnvLoading,
setGlobalEnvSaving,
setGlobalEnvError,
setGlobalEnvSuccess,
setProxyConfig,
setProxyLoading,
setProxySaving,
setProxyError,
setProxySuccess,
setProxyTestResult,
setProxyTesting,
setRawConfig,
setRawConfigLoading,
]
);
} }