useUrlState

一个同步组件内部状态和 query 参数的 hook。

API 有改动,见ahooks

Examples

Basic usage

API

const state = useUrlState(routerPush, DefaultState, {
  localStorageKey: 'localStorageKey',
});

interface UseUrlStateOptions {
  localStorageKey?: string;
}

Params

PropertyDescriptionTypeDefault
routerPushFnPass router.pushfunction-
initialStatedefaultValueS | (() => S)-
optionsIf set the options.localStorageKey is set, state will use the state saved in localStorage when url params is empty.UseUrlStateOptions-

Result

PropertyDescriptionType
statestate ref-

最近更新: