sungwoncho / compconv

Convert React components between function and class

Home Page:https://sungwoncho.github.io/compconv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compconv

Convert React component between function and class.

Install

npm install compconv

If you are using Yarn,

yarn install compconv

Usage

Let's convert a functional component to a class component.

import compconv from 'compconv';

const input = `export default ({ foo, bar  }) => {
  return (
    <div>
      This is {foo} {bar}
    </div>
  );
};`

const output = compconv(input);

// output is:
//
// export default class MyComponent extends React.Component {
//   render() {
//     return (
//       <div>
//         This is {this.props.foo} {this.props.bar}
//       </div>
//     )
//   }
// }

It also works the other way around.

License

MIT

About

Convert React components between function and class

https://sungwoncho.github.io/compconv

License:MIT License


Languages

Language:JavaScript 100.0%