mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 20:17:45 +00:00
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:
@@ -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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user