React convert to class component Follow
I'm trying to customize my template for converting a React functional component to class component. In Editor > General > File and Code Templates > Code tab > React Class Component I have modified to this:
class $!NAME extends PureComponent {
#if($PROP_TYPES)
static propTypes = $PROP_TYPES
#end
#if($DEFAULT_PROPS)
static defaultProps = $DEFAULT_PROPS
#end
render() {
return $COMPONENT_BODY
}
}
I have a simple component file:
import React from 'react';
import PropTypes from 'prop-types';
function Comp(props) {
const { classes } = props;
return <div className={classes.root}>Hello</div>;
}
Comp.propTypes = {
classes: PropTypes.object.isRequired
};
export default Comp;
When I convert to class component it doesn't move the propTypes into the class as a static field but leaves at the bottom.
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
class Comp extends PureComponent {
render() {
const { classes } = this.props;
return <div className={classes.root}>Hello</div>;
}
}
Comp.propTypes = {
classes: PropTypes.object.isRequired
};
export default Comp;
Any ideas on how the fix this?
Please sign in to leave a comment.
your template is correct and should work, but it doesn't:( please follow https://youtrack.jetbrains.com/issue/WEB-35600 for updates