gpt4 book ai didi

javascript - esLint如何检测which method 'should be placed after' another method?

转载 作者:行者123 更新时间:2023-11-30 14:12:07 26 4
gpt4 key购买 nike

很多时候,esLint 会提示一个方法应该放在另一个方法之后(我使用的是 React,所以我不确定它是否有所不同)。我只是想知道它推荐特定顺序的依据是什么?

我所知道的是,生命周期方法应该排在第一位(以正确的顺序),然​​后是自定义方法。但是 esLint 也会提示这些自定义方法的顺序,我不确定为什么?

最佳答案

根据 AirBnb react style guide这是 eslint 规则遵循的,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

关于javascript - esLint如何检测which method 'should be placed after' another method?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54230595/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com