有时候你想快速从无状态组件转到有状态组件,我想是否有办法让IntelliJ为我做这个(没有创建插件).
例如,从:
const Stateless = ({ propsDestructuring }) => {
console.log('Some logic');
return (
<div>Some JSX</div>
);
};
Run Code Online (Sandbox Code Playgroud)
至:
class Stateful extends Component {
render() {
const {
propsDestructuring
} = this.props;
console.log('Some logic');
return (
<div>Some JSX</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
或者从"箭头体型"到显式返回也是有用的,例如从
const Stateless = ({ propsDestructuring }) => (
<div>Some JSX</div>
);
Run Code Online (Sandbox Code Playgroud)
至:
const Stateless = ({ propsDestructuring }) => {
return (
<div>Some JSX</div>
);
};
Run Code Online (Sandbox Code Playgroud)
使用实时模板在这种情况下不起作用,因为它们不能改变现有代码,只能插入新代码.有什么建议?