How does esLint detect which method 'should be placed after' another method?

Viewed 1423

Often times, esLint would complain that a method should be placed after another method (I am using React so I'm not sure if it makes a difference). I am just wondering on what basis does it recommend a particular ordering?

All I know is that lifecycle methods should come first (in their proper order), then below them are the custom methods. But esLint would also complain about the ordering of those custom methods and I'm not sure why?

1 Answers

According to AirBnb react style guide which is what eslint rules follow, the ordering or method in React.Component shall be

  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
Related