Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/srph/react-hoc-compose

Compose factory components on the go for incredibly lazy people
https://github.com/srph/react-hoc-compose

react react-router

Last synced: about 1 month ago
JSON representation

Compose factory components on the go for incredibly lazy people

Awesome Lists containing this project

README

        

## React HOC Compose [![npm version](https://img.shields.io/npm/v/@srph/react-hoc-compose.svg?style=flat-square)](https://npmjs.com/packages/@srph/react-hoc-compose) [![Build Status](https://img.shields.io/travis/srph/react-hoc-compose.svg?style=flat-square)](https://travis-ci.org/srph/react-hoc-compose?branch=master)
Compose factory components (HOCs) on the go without variable assignment

## Why
You may find this useful if you're using [React Router v4](https://github.com/ReactTraining/react-router). The following no longer has "abstract" routes:

```js

```

If you do, you'll get the following console warning:
```
You should not use and in the same route; will be ignored
```

Instead, the library advices on doing the following:

```js

```

I use HOCs to apply permissions on each route (the following uses React Router as an example), like so:

```js




```

Since `` isn't a valid syntax, we will have to assign it to a variable.

```js
const AppMainWithPermission = Permission.auth(AppMain)
```

Which gets verbose overtime. What if we could compose it on the go?

```js


```

## How It Works
`Compose` applies the HOC to the component once, on initial mount.

## Installation
```bash
npm install @srph/react-hoc-compose --save
```

### Script tags
If you're not using a bundler like Browserify or Webpack, simply add the script tag after your React script tag.

```html

```

This library is exposed as `ReactHOCCompose` (e.g., ``).

## Usage
```js

```

## Contributing
```
npm test
```

### Bundling package
```
npm run bundle
```