1.2.0 • Published 11 months ago
react-router-toolkit v1.2.0
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;
}