快捷键

ReferenceCard.pdf
ReferenceCardForMac.pdf

快捷键创建React组件

rcc

用ES6模块系统创建一个React组件类

  1. import React, { Component } from 'react';
  2. class Index extends Component {
  3. render() {
  4. return (
  5. <div>
  6. </div>
  7. );
  8. }
  9. }
  10. export default Index;

rccp

创建一个带有PropTypes和ES6模块系统的React组件类

  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. class Index extends Component {
  4. render() {
  5. return (
  6. <div>
  7. </div>
  8. );
  9. }
  10. }
  11. Index.propTypes = {};
  12. export default Index;

rcfc

创建一个带有PropTypes和所有生命周期方法以及ES6模块系统的React组件类

  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. class Index extends Component {
  4. constructor(props) {
  5. super(props);
  6. }
  7. componentWillMount() {
  8. }
  9. componentDidMount() {
  10. }
  11. componentWillReceiveProps(nextProps) {
  12. }
  13. shouldComponentUpdate(nextProps, nextState) {
  14. }
  15. componentWillUpdate(nextProps, nextState) {
  16. }
  17. componentDidUpdate(prevProps, prevState) {
  18. }
  19. componentWillUnmount() {
  20. }
  21. render() {
  22. return (
  23. <div>
  24. </div>
  25. );
  26. }
  27. }
  28. Index.propTypes = {};
  29. export default Index;

rcjc

用ES6模块系统创建一个React组件类(无导出)

  1. class Index extends Component {
  2. render() {
  3. return (
  4. <div>
  5. </div>
  6. );
  7. }
  8. }

rdp

快速生成defaultProps

  1. .defaultProps = {
  2. ,
  3. };

rpc

用PropTypes和ES6 moudle系统创建一个React纯组件类

  1. import React, { PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. class Index extends PureComponent {
  4. render() {
  5. return (
  6. <div>
  7. </div>
  8. );
  9. }
  10. }
  11. Index.propTypes = {};
  12. export default Index;

rrc

创建一个连接到redux的React组件类

  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. function mapStateToProps(state) {
  4. return {};
  5. }
  6. class Index extends Component {
  7. render() {
  8. return (
  9. <div>
  10. </div>
  11. );
  12. }
  13. }
  14. export default connect(
  15. mapStateToProps,
  16. )(Index);

rrdc

创建一个通过dispatch连接到redux的React组件类

  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. function mapStateToProps(state) {
  4. return {};
  5. }
  6. function mapDispatchToProps(dispatch) {
  7. return {};
  8. }
  9. class Index extends Component {
  10. render() {
  11. return (
  12. <div>
  13. </div>
  14. );
  15. }
  16. }
  17. export default connect(
  18. mapStateToProps,
  19. )(Index);

rsc

创建没有PropTypes和ES6模块系统的无状态React组件

  1. import React from 'react';
  2. const Index = () => {
  3. return (
  4. <div>
  5. </div>
  6. );
  7. };
  8. export default Index;

rscp

创建有PropTypes和ES6模块系统的无状态React组件

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. const Index = props => {
  4. return (
  5. <div>
  6. </div>
  7. );
  8. };
  9. Index.propTypes = {
  10. };
  11. export default Index;

rsf

以命名函数的形式创建无状态的React组件,不使用PropTypes

  1. import React from 'react';
  2. function Index(props) {
  3. return (
  4. <div></div>
  5. );
  6. }
  7. export default Index;

rsfp

使用PropTypes将无状态的React组件作为命名函数创建

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. Index.propTypes = {
  4. };
  5. function Index(props) {
  6. return (
  7. <div></div>
  8. );
  9. }
  10. export default Index;

rsi

创建无状态的React组件,不使用PropTypes和ES6模块系统,但使用隐式返回和道具

  1. import React from 'react';
  2. const Index = (props) => (
  3. );
  4. export default Index;

rwwd

在没有导入的情况下,在ES6模块系统中创建一个有构造函数、空状态、proptypes和导出的React组件类。(主要用于React时,proptype由webpack提供插件提供)

  1. class Index extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {};
  5. }
  6. render() {
  7. return (
  8. <div>
  9. </div>
  10. );
  11. }
  12. }
  13. Index.propTypes = {};
  14. export default Index;