Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/beanloop/react-with-params

React HOC for extracting router params.
https://github.com/beanloop/react-with-params

higher-order-component react-router react-router-v4

Last synced: about 2 months ago
JSON representation

React HOC for extracting router params.

Awesome Lists containing this project

README

        

# react-with-params
[![Build Status](https://travis-ci.org/beanloop/react-with-params.svg?branch=master)](https://travis-ci.org/beanloop/react-with-params)
[![npm version](https://badge.fury.io/js/react-with-params.svg)](https://badge.fury.io/js/react-with-params)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)

React HOC for extracting router params.

## Install
```
yarn add react-with-params
npm install --save react-with-params
```

## Usage
```typescript
import Route from 'react-router/Route'
import {withParams} from 'react-with-params'

const ShowName = withParams({params: 'name', match: '/user/:name'})(({name}) =>
{name}
)

```

```typescript
import Route from 'react-router/Route'
import {withParams} from 'react-with-params'

const ShowNameAndId = withParams({params: ['name', 'id'], match: '/user/:name/:id'})(({name, id}) =>
{id} - {name}
)

```

### Query parameters
```typescript
import Route from 'react-router/Route'
import {withParams} from 'react-with-params'

const Display = withParams({
queryParams: 'next',
match: '/users',
})(({next}) =>
{next}
)

```

```typescript
import Route from 'react-router/Route'
import {withParams} from 'react-with-params'

const Display = withParams({
queryParams: ['next', 'timestamp'],
match: '/users',
})(({next, timestamp}) =>
{next} - {timestamp}
)

```

## License
react-with-params is dual-licensed under Apache 2.0 and MIT
terms.