UNPKG

react-use-url-state

Version:
21 lines (20 loc) 847 B
import { z } from 'zod'; export type UrlStateOptions = { /** * If true, the initial value will be applied to the URL. */ applyInitialValue: boolean; }; export type UrlStateValue<T extends DefaultSchema> = z.infer<T>; export type UrlState<T extends DefaultSchema> = { data: UrlStateValue<T> | null; isError: boolean; isReady: boolean; error: z.ZodError | null; }; export type UrlStateMethods<T extends DefaultSchema> = { setState: (state: UrlStateValue<T> | ((state: UrlStateValue<T> | null) => UrlStateValue<T>)) => void; setValue: <K extends keyof z.infer<T>>(key: K, value: UrlStateValue<T>[K]) => void; setValues: (state: Partial<UrlStateValue<T>> | ((state: UrlStateValue<T> | null) => Partial<UrlStateValue<T>>)) => void; }; export type DefaultSchema = z.ZodObject<Record<string, z.ZodTypeAny>>;