https://github.com/space-fe/react-use-querystring-state
Mapping query string from url to Component state seamlessly
https://github.com/space-fe/react-use-querystring-state
qs querystring reacthooks usestate
Last synced: 10 months ago
JSON representation
Mapping query string from url to Component state seamlessly
- Host: GitHub
- URL: https://github.com/space-fe/react-use-querystring-state
- Owner: space-fe
- Created: 2020-02-15T03:02:04.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T14:01:58.000Z (almost 3 years ago)
- Last Synced: 2025-02-28T12:19:07.124Z (11 months ago)
- Topics: qs, querystring, reacthooks, usestate
- Language: TypeScript
- Homepage:
- Size: 446 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-use-querystring-state
Mapping query string from url to Component state seamlessly, You can migrate from React `useState` to `useQueryStringState` at no cost.
[react-use-querystring-state](https://github.com/space-fe/react-use-querystring-state)
## Installation
Use `npm`
```shell
npm install react-use-querystring-state
```
## Usage
You can save a state such as string, object and any JSON stringify value.
### string
```javascript
import React, { useState } from 'react'
import useQueryStringState from 'react-use-querystring-state'
// useState
//
// const [key1State, setKey1State] = useState('keyword')
const [key1State, setKey1State] = useQueryStringState('key1', 'keyword')
```
### object
```javascript
import React, { useState } from 'react'
import useQueryStringState from 'react-use-querystring-state'
// useState
//
// const [key2State, setKey2State] = useState({ a: '1', b: '2' })
const [key1State, setKey1State] = useQueryStringState('key2', { a: '1', b: '2' })