React Routeways - API Reference • Docs
React Routeways - API Reference / useQueryParam
Function: useQueryParam()
useQueryParam(route, key)
useQueryParam<
Q
,K
>(route
,key
):UseQueryParam
<Optional
<CodecsToRecord
<Q
>[K
]>>
Returns a tuple of a stateful value of the specified query param, and a function to update it. Just like the useState hook would.
However, because the source of truth for this state is the current url, whenever the state is updated in one component, it will be also updated in other components using the same query param state. This keeps consistency across the state and the URL all the time.
Type Parameters
• Q extends CodecMap
• K extends string
Parameters
• route: Routeway
<`/${string}`, CodecMap
, Q
>
the Routeway
route to use to parse the query param
• key: K
the key of the specific query param to use
Returns
UseQueryParam
<Optional
<CodecsToRecord
<Q
>[K
]>>
a stateful value of the query param, and a function to update it
Defined in
src/lib/hooks/useQueryParam.hook.ts:31
useQueryParam(route, key, fallback)
useQueryParam<
Q
,K
>(route
,key
,fallback
):UseQueryParam
<NonOptional
<CodecsToRecord
<Q
>[K
]>>
Returns a tuple of a stateful value of the specified query param, and a function to update it. Just like the useState hook would.
However, because the source of truth for this state is the current location, whenever the state is updated in one component, it will be also updated in other components using the same query param state. This keeps consistency across the state and the location all the time.
Type Parameters
• Q extends CodecMap
• K extends string
Parameters
• route: Routeway
<`/${string}`, CodecMap
, Q
>
the Routeway
route to use to parse the query param
• key: K
the key of the specific query param to use
• fallback: CodecsToRecord
<Q
>[K
]
an optional fallback value in case the query param is not
present in the url, undefined
, or null
Returns
UseQueryParam
<NonOptional
<CodecsToRecord
<Q
>[K
]>>
a stateful value of the query param, and a function to update it