Skip to content
On this page

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

PropertyDescriptionTypeDefault
initialStatedefaultS | () => S-
optionsWhen setting localStorageKey, if url has no parameter, the value of localStorage is used
UseUrlStateOptions-routerPushFn

Result

PropertyDescriptionType
stateUrl query object-

Source

SourceDocsDemo