Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ncpa0cpl/react-router-use-url-query-state
https://github.com/ncpa0cpl/react-router-use-url-query-state
Last synced: about 10 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/ncpa0cpl/react-router-use-url-query-state
- Owner: ncpa0cpl
- Created: 2021-07-10T11:15:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-06T13:45:27.000Z (about 3 years ago)
- Last Synced: 2024-02-20T17:52:06.626Z (9 months ago)
- Language: TypeScript
- Size: 118 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React Router - Use URL Query State
React hook that leverages the React Router to create a state that's synchronized with the query parameters in the browser url.
## Usage
Use just like a React's `useState` hook:
```ts
// for a string value
const [myStateValue, setMyStateValue] = useURLQueryState(
"parameterName",
"initialValue"
);// for a string list value
const [myStateValue, setMyStateValue] = useURLQueryState("parameterName", [
"initial",
"values",
]);
```Value stored in the URL Query State must be either a string or a list of strings. It can be only one of these types, cannot be both.