Basic usage
Simply run Migrate to React class command to convert React stateless components to React class components.
Additionally, if the file is TypeScript React (*.tsx ), this also converts PropTypes to type definitions accordingly.
// Before
class MyComponent extends React.Component {
static propTypes = {
className: PropTypes.string,
children: PropTypes.node.isRequired,
}
state = { visible: false }
render() {
return <div></div>
}
}
// After
class MyComponent extends React.Component<{
className?: string
children: React.ReactNode
}, { visible: boolean }> {
constructor(props) {
super(props)
this.state = { visible: false }
}
render() {
return <div></div>
}
}
| |