Files
paseo/packages/plugin/src/client/tab.ts
T
Mohamed Boudra 4fe006df86 feat(plugins): unify panel props and persist tab state (#7685)
* feat(plugins): unify panel props and persist tab state

* refactor(plugins): make agent panel registration canonical

* docs(plugins): update Chinese panel API reference and migration
2026-10-23 13:26:19 +07:00

17 lines
691 B
TypeScript

import { useCallback, useMemo } from "react";
import type { JsonValue } from "@getpaseo/protocol/agent-types";
import type { ZodType } from "zod";
import type { PluginTab } from "./contracts.js";
/** Validates the panel's persisted state, using the default for missing or invalid values. */
export function useTabState<T extends JsonValue>(
tab: PluginTab,
schema: ZodType<T>,
defaultState: T,
): [T, (next: T) => void] {
const parsed = useMemo(() => schema.safeParse(tab.state), [schema, tab.state]);
const writeState = tab.setState;
const setState = useCallback((next: T) => writeState(next), [writeState]);
return [parsed.success ? parsed.data : defaultState, setState];
}