useUrlState
A hook that store the state into url query.
Code demonstration
API
const state = useUrlState(defaultState, {
localStorageKey: 'localStorageKey',
routerPushFn,
})
interface UseUrlStateOptions {
localStorageKey?: string
}
const state = useUrlState(defaultState, {
localStorageKey: 'localStorageKey',
routerPushFn,
})
interface UseUrlStateOptions {
localStorageKey?: string
}
Params
Property | Description | Type | Default |
---|---|---|---|
initialState | default | S | () => S | - |
options | When setting localStorageKey , if url has no parameter, the value of localStorage is used | ||
UseUrlStateOptions | - | routerPushFn |
Result
Property | Description | Type |
---|---|---|
state | Url query object | - |