babel-plugin-transform-react-render-parameters

0.4.0 • Public • Published

babel-plugin-transform-react-render-parameters

Allow props and state as render() parameters, as in preact.

Example

In

class Test extends Component {
  render(props, { a, b }, ctx) {
    return <div />;
  }
}

Out

class Test extends Component {
  render() {
    const props = this.props,
          { a, b } = this.state || {},
          ctx = this.context;

    return <div />;
  }
}

Installation

$ npm install --dev babel-plugin-transform-react-render-parameters

Usage

.babelrc

{
  "plugins": ["transform-react-render-parameters"]
}

The render method will be changed for classes with Component or PureComponent as their superclass by default. To change this, add the superClasses option:

{
  "plugins": [
    ["transform-react-render-parameters", {
      "superClasses": ["Component", "MyBaseComponent"]
    }]
  ]
}

Limitations

This plugin currently only supports class methods defined within the class syntax. As a result, it won't work with React.createClass(). If you are using a plugin which transforms the class syntax, this plugin needs to come before that one in the plugins array. This plugin will work fine if the other plugin is part of a preset, as well.

Package Sidebar

Install

npm i babel-plugin-transform-react-render-parameters

Weekly Downloads

1

Version

0.4.0

License

MIT

Unpacked Size

10.8 kB

Total Files

64

Last publish

Collaborators

  • matt-tingen