import type { Dispatch, SetStateAction } from 'react'; import type { ZodType } from 'zod'; import { useLocalStorageState } from '../../hooks/useLocalStorageState'; export function useUserPreferenceState({ key, schema, }: { key: string; schema?: ZodType; }): [T, Dispatch>] { const [value, set] = useLocalStorageState(`UserPerf.${key}`, { defaultValue: (() => { try { return schema?.parse({}) || {}; } catch (e) {} return {}; }) as () => T, }); return [value, set]; }