state-in-url
Version:
Store state in URL as in object, types and structure are preserved, with TS validation. Same API as React.useState, wthout any hasssle or boilerplate. Next.js@14-15 and react-router@6-7.
14 lines (13 loc) • 592 B
TypeScript
import { type JSONCompatible } from "./utils";
/**
* Parses the Next.js server-side `searchParams` into an object.
*
* Or with react-router
* {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState/useUrlState.ts}
*
*
* @param {object | undefined} sp - The server-side searchParams object to parse.
* @param {T} defaults - The default values to use if parsing fails.
* @return {T} - The parsed object or the default values.
*/
export declare function parseSPObj<T extends JSONCompatible>(sp: object | undefined, defaults: T): T;