react-router-toolkit
v1.2.0
Published
some tool functions and hooks to react-router
Downloads
115
Maintainers
Readme
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;
}