美文网首页
webStrom快捷键快速创建React组件

webStrom快捷键快速创建React组件

作者: 稚儿擎瓜_细犬逐蝶 | 来源:发表于2019-12-12 10:43 被阅读0次

参考地址: 超级吴小迪

  1. rcc + tab键 - - 用ES6模块系统创建一个React组件类
class Index extends Component {
  render() {
    return (
      <div>
        
      </div>
    );
  }
}
export default Index;
  1. rccp + tab键 - - 创建一个带有PropTypes和ES6模块系统的React组件类
class Index extends Component {
  render() {
    return (
      <div>
        
      </div>
    );
  }
}

Index.propTypes = {};

export default Index;
  1. rcfc + tab键 - - 创建一个带有PropTypes和所有生命周期方法以及ES6模块系统的React组件类
import React, {Component} from 'react';
import PropTypes from 'prop-types';

class Index extends Component {
  constructor(props) {
    super(props);

  }

  componentWillMount() {}

  componentDidMount() {}

  componentWillReceiveProps(nextProps) {}

  shouldComponentUpdate(nextProps, nextState) {}

  componentWillUpdate(nextProps, nextState) {}

  componentDidUpdate(prevProps, prevState) {}

  componentWillUnmount() {}

  render() {
    return (
      <div>

      </div>
    );
  }
}

Index.propTypes = {};

export default Index;
  1. rcjc + tab键 - - 用ES6模块系统创建一个React组件类(无导出)
class Index extends Component {
render() {
 return (
   <div>
     
   </div>
 );
}
}
下面的自己可以尝试一下哦,笔者只是做了介绍就不放图了~
  1. rdp + tab键 - - 快速生成defaultProps
.defaultProps = {
  
};
  1. rpc + tab键 - - 用PropTypes和ES6 moudle系统创建一个React纯组件类
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';

class Index extends PureComponent {
  render() {
    return (
      <div>
        
      </div>
    );
  }
}

Index.propTypes = {};

export default Index;
  1. rrc + tab键 - - 创建一个连接到redux的React组件类
import React, {Component} from 'react';
import {connect} from 'react-redux';

function mapStateToProps(state) {
  return {};
}

class Index extends Component {
  render() {
    return (
      <div>
        
      </div>
    );
  }
}

export default connect(
  mapStateToProps,
)(Index);
  1. rrdc + tab键 - - 创建一个通过dispatch连接到redux的React组件类
import React, {Component} from 'react';
import {connect} from 'react-redux';

function mapStateToProps(state) {
  return {};
}

function mapDispatchToProps(dispatch) {
  return {};
}

class Index extends Component {
  render() {
    return (
      <div>
        
      </div>
    );
  }
}

export default connect(
  mapStateToProps,
)(Index);
  1. rsc + tab键 - - 创建没有PropTypes和ES6模块系统的无状态React组件
import React from 'react';

const Index = () => {
  return (
    <div>
      
    </div>
  );
};

export default Index;
  1. rscp + tab键 - - 创建有PropTypes和ES6模块系统的无状态React组件
import React from 'react';
import PropTypes from 'prop-types';

const Index = props => {
  return (
    <div>

    </div>
  );
};

Index.propTypes = {
  
};

export default Index;
  1. rsf + tab键 - - 以命名函数的形式创建无状态的React组件,不使用PropTypes
import React from 'react';

function Index(props) {
  return (
    <div></div>
  );
}

export default Index;
  1. rsfp + tab键 - - 使用PropTypes将无状态的React组件作为命名函数创建
import React from 'react';
import PropTypes from 'prop-types';

Index.propTypes = {
  
};

function Index(props) {
  return (
    <div></div>
  );
}

export default Index;
  1. rsi + tab键 - - 创建无状态的React组件,不使用PropTypes和ES6模块系统,但使用隐式返回和道具
import React from 'react';

const Index = (props) => (
  
);

export default Index;
  1. rwwd + tab键 - - 在没有导入的情况下,在ES6模块系统中创建一个有构造函数、空状态、proptypes和导出的React组件类。(主要用于React时,proptype由webpack提供插件提供)
class Index extends React.Component {
  constructor(props) {
    super(props);

    this.state = {};

  }

  render() {
    return (
      <div>
        
      </div>
    );
  }
}

Index.propTypes = {};

export default Index;

相关文章

网友评论

      本文标题:webStrom快捷键快速创建React组件

      本文链接:https://www.haomeiwen.com/subject/paeevctx.html