最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ESLint rule to disallow useEffect without dependency list - Stack Overflow

programmeradmin1浏览0评论

Is there an ESLint rule for React to disallow writing useEffect without dependency list?

I'm looking for something like this:

useEffect(() => {
  if (error) handleError(error)
}) // ❌ I expect ESLint complains here, because there's no dependency list
useEffect(() => {
  if (error) handleError(error)
}, [error]) // ✅ Now it has an explicit dependency list

Note that react-hooks/exhaustive-deps doesn't serve that purpose. It complains if the useEffect includes a dependency list but is not exhaustive — for instance, using an empty array ([]) instead of [error], in the second snippet.

发布评论

评论列表(0)

  1. 暂无评论