mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 18:18:43 +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
|
* 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,
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user