react-use-url-state
Version:
React hook for managing state in the URL
18 lines (17 loc) • 1.1 kB
TypeScript
import { DefaultSchema, UrlStateOptions } from './types';
export type { DefaultSchema, UrlState } from './types';
/**
* Creates a hook that will manage the state of the URL search params.
* @param {z.ZodObject} schema - zod schema to verify the url state
* @param {UrlStateOptions} [options]
* @param {boolean} [options.applyInitialValue] - if true, the initial value will be applied to the URL
*/
export declare function useUrlState<T extends DefaultSchema>(schema: T, options?: UrlStateOptions): {
setState: (state: import("./types").UrlStateValue<T> | ((state: import("./types").UrlStateValue<T> | null) => import("./types").UrlStateValue<T>)) => void;
setValue: <K extends keyof import("zod").TypeOf<T>>(key: K, value: import("./types").UrlStateValue<T>[K]) => void;
setValues: (state: Partial<import("./types").UrlStateValue<T>> | ((state: import("./types").UrlStateValue<T> | null) => Partial<import("./types").UrlStateValue<T>>)) => void;
data: import("./types").UrlStateValue<T> | null;
isError: boolean;
isReady: boolean;
error: import("zod").ZodError | null;
};