react-router-toolkit
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

API

parseQueryString: queryString to queryMap
const queryString = 'name=zhangshan&age=18&height=180'
const queryString2 = '?name=zhangshan&age=18&height=180'

const queryMap = parseQueryString(queryString)
const queryMap2 = parseQueryString(queryString2)
toQueryString: queryMap to queryString
const queryMap = {
  name: 'zhangshan',
  age: 18,
  height: 180,
}

const queryString = toQueryString(queryMap)
useRouterQuery: quick get query and set query
interface IQueryMap {
  name: string;
  age: string;
  height: string;
  loves: ParsedUrlQuery;
}

const [routerRuery, setRouterQuery] = useRouterQuery<IQueryMap>();
const name = routerRuery.name;
const loves = routerRuery.loves;
// or
const [{ name, loves }, setRouterQuery] = useRouterQuery<IQueryMap>();

setRouterQuery((preState) => ({
  ...preState,
  name: "lisi",
}));

common interface

Dictionary
interface Dictionary<T> {
  [key: string]: T;
}
ParsedUrlQueryValue
type ParsedUrlQueryValue = string | string[];
ParsedUrlQuery
interface ParsedUrlQuery {
  [key: string]: ParsedUrlQueryValue;
}

Package Sidebar

Install

npm i react-router-toolkit

Weekly Downloads

18

Version

1.2.0

License

MIT

Unpacked Size

6.51 kB

Total Files

12

Last publish

Collaborators

  • rookie-luochao