Skip to content

Commit e696388

Browse files
authored
docs(use-query-params): improve README (#156)
1 parent 190a7ce commit e696388

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

packages/use-query-params/README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
## Install
66

77
```bash
8-
$ yarn add @scaleway/use-query-params
8+
$ yarn add @scaleway/use-query-params react-router-dom
99
```
1010

1111
## Usage
12-
1312
```js
1413
import React from 'react'
14+
import { render } from 'react-dom'
15+
import { BrowserRouter as Router } from "react-router-dom";
1516
import useQueryParams from '@scaleway/use-query-params'
1617

17-
// this component should be wrap with a Router
18-
const Component = () => {
18+
const App = () => {
1919
const { queryParams, setQueryParams } = useQueryParams()
2020
const { user } = queryParams
2121
const setUser = () => setQueryParams({ user: 'John' })
@@ -28,28 +28,34 @@ const Component = () => {
2828
</>
2929
)
3030
}
31+
32+
render(
33+
<Router>
34+
<App />
35+
</Router>,
36+
document.getElementById('react-root'),
37+
)
3138
```
3239

3340
### Set query params
3441

3542
Merge current query params with the new ones passed in parameters.
3643

3744
```js
38-
//In this exemple we admit that we have an URL that include : `?compagny=Scaleway".
45+
// In this exemple we assume that we have an URL that include : `?company=Scaleway".
3946
import React from 'react'
4047
import useQueryParams from '@scaleway/use-query-params'
4148

42-
// this component should be wrap with a Router
4349
const Component = () => {
4450
const { queryParams, setQueryParams } = useQueryParams()
45-
const { user, compagny } = queryParams // user will be undefined and compagny will be "Scaleway"
46-
const setUser = () => setQueryParams({ user: 'John' }) // user will be "John" and compagny will be "Scaleway"
47-
// ?compagny=Scaleway&user=John
51+
const { user, company } = queryParams // user will be undefined and company will be "Scaleway"
52+
const setUser = () => setQueryParams({ user: 'John' }) // user will be "John" and company will be "Scaleway"
53+
// ?company=Scaleway&user=John
4854

4955
return (
5056
<>
5157
<h1>User: {user}</h1>
52-
<h1>Compagny: {compagny}</h1>
58+
<h1>Company: {company}</h1>
5359
<button onClick={setUser}>Set User John</button>
5460
</>
5561
)
@@ -61,21 +67,20 @@ const Component = () => {
6167
Erase current query params and replace by the new ones passed in parameters.
6268

6369
```js
64-
//In this exemple we admit that we have an URL that include : `?compagny=Scaleway".
70+
// In this exemple we assume that we have an URL that include : `?company=Scaleway".
6571
import React from 'react'
6672
import useQueryParams from '@scaleway/use-query-params'
6773

68-
// this component should be wrap with a Router
6974
const Component = () => {
7075
const { queryParams, setQueryParams } = useQueryParams()
71-
const { user, compagny } = queryParams // user will be undefined and compagny will be "Scaleway"
72-
const setUser = () => replaceQueryParams({ user: 'John' }) // user will be "John" and compagny will be undefined
76+
const { user, company } = queryParams // user will be undefined and company will be "Scaleway"
77+
const setUser = () => replaceQueryParams({ user: 'John' }) // user will be "John" and company will be undefined
7378
// ?user=John
7479

7580
return (
7681
<>
7782
<h1>User: {user}</h1>
78-
<h1>Compagny: {compagny}</h1>
83+
<h1>Company: {company}</h1>
7984
<button onClick={setUser}>Set User John</button>
8085
</>
8186
)

0 commit comments

Comments
 (0)