> The fastest way to use Query String as State
npm install use-query-stateuseQueryStateView Demo
npm install use-query-state
`Usage
> just like setStateBasic
`js
import useQueryState from 'use-query-state';const App = () => {
const [name, setName] = useQueryState('', 'name');
return (
{ name }
);
}
`Advanced
`js
import useQueryState from 'use-query-state';const App = () => {
const [input, setInput] = useQueryState('hello world', 'input', { action: 'replace', delay: 300 });
const onInputChange = (event) => {
setInput(event.target.value);
};
return (
);
}
`API
$3
#### DefaultValue
- Type:
string | boolean | number | string[]
- Required: true
- Description: the value is used when query parameter is undefined#### QueryParamName
- Type:
string
- Required: true
- Description: the valued is used as the query parameter name#### Options
- Type:
`js
{
action?: 'push' | 'replace',
delay?: number
}
`
- Required: false
- Description:
action is defining how to mutate the history state. action defaults to 'push'.
delay is defining the debounce wait time for mutating the history state when using Setter.
delay defaults to 0.#### Value
- Type:
string | boolean | number | string[] | undefined | null
- Description: the returned value for read#### Setter
- Type:
(value: Value): void`