Optimize React code by making pure classes into functions
Note: Requires React v0.14 or higher.
In:
class MyComponent extends React.Component {
static propTypes = {
className: React.PropTypes.string.isRequired
};
render() {
return (
<div className={this.props.className}>
...
</div>
);
}
}
Out:
function MyComponent(props) {
return (
<div className={props.className}>
...
</div>
);
}
MyComponent.propTypes = {
className: React.PropTypes.string.isRequired
};
$ npm install babel-plugin-react-pure-components
.babelrc
{
"plugins": ["react-pure-components"]
}
$ babel --plugins react-pure-components script.js
require("babel-core").transform("code", {
plugins: ["react-pure-components"]
});