useQueryParameters
3p-core / useQueryParameters
Function: useQueryParameters()
useQueryParameters<
T
>(parameter
):IUseQueryParameters
<T
>
A React hook for reading and writing hash-based query parameters from the URL.
This is useful in single-page applications or SPFx web parts where routing and state preservation across reloads is needed.
Type Parameters
T
T
The expected type of the parameter value (must be serializable to JSON).
Parameters
parameter
string
The name of the query parameter to manage.
Returns
An object containing the current value
and a setParameter
function.
Example
const { value, setParameter } = useQueryParameters<number>('OpenItem');
React.useEffect(() => {
if (value) {
console.log('Opening item ID:', value);
}
}, [value]);
// Later, to update the parameter
setParameter(123);