extract-hoc-compose

Babel plugin which extracts HOCs from compose method so react-hot-loader can handle them.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
extract-hoc-compose
000.0.15 years ago5 years agoMinified + gzip package size for extract-hoc-compose in KB

Readme

extract-hoc-compose
Super simple and super dumb babel plugin that extracts HOCs from compose method, enabling simultaneous usage of react-hot-loader and recompose.

What it does

It converts this: ``` const EnhancedComponent = compose(
enhancer1,
enhanver2,
enhancer3
)(Component); ``` Into this: ``` const uid = enhancer3(Component); const uid2 = enhanver2(uid); const EnhancedComponent = enhancer1(uid2); ``` Single variable declaration and 'compose' name are required.

Installation

``` $ yarn add extract-hoc-compose -D -E ``` Add "extract-hoc-compose/babel" to your Babel plugins before "react-hot-loader/babel".

Caveats

The plugin must run before 'react-hot-loader/babel', however Babel 6 does not respect plugin ordering. With webpack, possible solution is to run babel-loader twice: ``` rules:
{
test: /\.jsx?$/,
use: [
'babel-loader',
{
loader: 'babel-loader',
options: {
plugins: ["extract-hoc-compose/babel"],
babelrc: false
}
},
],
exclude: [/node_modules/]
},
```

See also

Inspired by extract-hoc.

License

MIT