Ordering

  • Ordering for class extends React.Component:
  1. optional static methods
  2. constructor
  3. getChildContext
  4. componentWillMount
  5. componentDidMount
  6. componentWillReceiveProps
  7. shouldComponentUpdate
  8. componentWillUpdate
  9. componentDidUpdate
  10. componentWillUnmount
  11. clickHandlers or eventHandlers like onClickSubmit() or onChangeDescription()
  12. getter methods for render like getSelectReason() or getFooterContent()
  13. optional render methods like renderNavigation() or renderProfilePicture()
  14. render
  • How to define propTypes, defaultProps, contextTypes, etc…

    1. import React from 'react';
    2. import PropTypes from 'prop-types';
    3. const propTypes = {
    4. id: PropTypes.number.isRequired,
    5. url: PropTypes.string.isRequired,
    6. text: PropTypes.string,
    7. };
    8. const defaultProps = {
    9. text: 'Hello World',
    10. };
    11. class Link extends React.Component {
    12. static methodsAreOk() {
    13. return true;
    14. }
    15. render() {
    16. return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>;
    17. }
    18. }
    19. Link.propTypes = propTypes;
    20. Link.defaultProps = defaultProps;
    21. export default Link;
  • Ordering for React.createClass: eslint: react/sort-comp

  1. displayName
  2. propTypes
  3. contextTypes
  4. childContextTypes
  5. mixins
  6. statics
  7. defaultProps
  8. getDefaultProps
  9. getInitialState
  10. getChildContext
  11. componentWillMount
  12. componentDidMount
  13. componentWillReceiveProps
  14. shouldComponentUpdate
  15. componentWillUpdate
  16. componentDidUpdate
  17. componentWillUnmount
  18. clickHandlers or eventHandlers like onClickSubmit() or onChangeDescription()
  19. getter methods for render like getSelectReason() or getFooterContent()
  20. optional render methods like renderNavigation() or renderProfilePicture()
  21. render