fix(config): stabilize config hook callbacks to prevent action/filter flicker
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* React hook for loading and updating a single parsed action config.
|
||||
*/
|
||||
|
||||
import { useCallback } from "react";
|
||||
import { useConfigItem } from "./useConfigItem";
|
||||
import { fetchAction, updateAction } from "../api/config";
|
||||
import type { ActionConfig, ActionConfigUpdate } from "../types/config";
|
||||
@@ -23,12 +24,18 @@ export interface UseActionConfigResult {
|
||||
* @param name - Action base name (e.g. ``"iptables"``).
|
||||
*/
|
||||
export function useActionConfig(name: string): UseActionConfigResult {
|
||||
const fetchFn = useCallback(() => fetchAction(name), [name]);
|
||||
const saveFn = useCallback(
|
||||
(update: ActionConfigUpdate) => updateAction(name, update),
|
||||
[name],
|
||||
);
|
||||
|
||||
const { data, loading, error, saving, saveError, refresh, save } = useConfigItem<
|
||||
ActionConfig,
|
||||
ActionConfigUpdate
|
||||
>({
|
||||
fetchFn: () => fetchAction(name),
|
||||
saveFn: (update) => updateAction(name, update),
|
||||
fetchFn,
|
||||
saveFn,
|
||||
mergeOnSave: (prev, update) =>
|
||||
prev
|
||||
? {
|
||||
|
||||
Reference in New Issue
Block a user