Skip to content

ahooks 使用过程中,针对 eslint 需要做什么处理,才能让 useEffect 的依赖列表不用加入相关的依赖? #2252

Answered by liuyib
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

目前没有办法区分,这是 react 相关生态的问题。只能通过把 error 改成 warn 来缓解:

{
  "plugins": [
    // ...
    "react-hooks"
  ],
  "rules": {
    // 加上这个
    "react-hooks/exhaustive-deps": "warn"
  }
}

不想这样干的话,那就按照这个插件提示的那样,把需要放入依赖数组的东西都放进去。


依赖数组里的参数应该放多少,这是个颇具有争议的事情,useEffectEvent 这个新 hook 的出现(不需要写依赖数组),貌似就是来解决这个争议的,见:https://zhuanlan.zhihu.com/p/514751791(注:文中的 useEvent 就是这个 useEffectEvent,更换了名字,见:https://github.com/facebook/react/pull/25881)。

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@ghost
Comment options

@liuyib
Comment options

@ghost
Comment options

@liuyib
Comment options

@liuyib
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant