useUrlState
一个同步组件内部状态和 query 参数的 hook。
API 有改动,见ahooks。
Examples
Basic usage
API
const state = useUrlState(routerPush, DefaultState, {
localStorageKey: 'localStorageKey',
});
interface UseUrlStateOptions {
localStorageKey?: string;
}
Params
Property | Description | Type | Default |
---|---|---|---|
routerPushFn | Pass router.push | function | - |
initialState | defaultValue | S | (() => S) | - |
options | If set the options.localStorageKey is set, state will use the state saved in localStorage when url params is empty. | UseUrlStateOptions | - |
Result
Property | Description | Type |
---|---|---|
state | state ref | - |