Skip to content

Commit be0c7e4

Browse files
committed
doc: Add query parameter examples
doc: Update doc to match the latest API
1 parent 64b8554 commit be0c7e4

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ npm install --save react-with-params
1616
import Route from 'react-router/Route'
1717
import {withParams} from 'react-with-params'
1818

19-
const ShowName = withParams('name', {match: '/user/:name'})(({name}) =>
19+
const ShowName = withParams({params: 'name', match: '/user/:name'})(({name}) =>
2020
<span>{name}</span>
2121
)
2222

@@ -27,13 +27,42 @@ const ShowName = withParams('name', {match: '/user/:name'})(({name}) =>
2727
import Route from 'react-router/Route'
2828
import {withParams} from 'react-with-params'
2929

30-
const ShowNameAndId = withParams(['name', 'id'], {match: '/user/:name/:id'})(({name, id}) =>
30+
const ShowNameAndId = withParams({params: ['name', 'id'], match: '/user/:name/:id'})(({name, id}) =>
3131
<span>{id} - {name}</span>
3232
)
3333

3434
<Route exact path='/user/:name/:id' component={ShowNameAndId} />
3535
```
3636

37+
### Query parameters
38+
```typescript
39+
import Route from 'react-router/Route'
40+
import {withParams} from 'react-with-params'
41+
42+
const Display = withParams({
43+
queryParams: 'next',
44+
match: '/users',
45+
})(({next}) =>
46+
<span>{next}</span>
47+
)
48+
49+
<Route exact path='/users' component={Display} />
50+
```
51+
52+
```typescript
53+
import Route from 'react-router/Route'
54+
import {withParams} from 'react-with-params'
55+
56+
const Display = withParams({
57+
queryParams: ['next', 'timestamp'],
58+
match: '/users',
59+
})(({next, timestamp}) =>
60+
<span>{next} - {timestamp}</span>
61+
)
62+
63+
<Route exact path='/users' component={Display} />
64+
```
65+
3766
## License
3867
react-with-params is dual-licensed under Apache 2.0 and MIT
3968
terms.

0 commit comments

Comments
 (0)