是否有强制仅使用功能性 setState 的 eslint-react 规则?

Is there eslint-react rule that forces to use functional setState only?

我积极使用 eslint-plugin-react,最近阅读了 functional setState。我想为此使用 eslint 规则,但找不到。是否有强制仅使用功能性 setState 的 eslint-react 规则?

简答

目前没有这样的 eslint-plugin-react 规则可用。

附加信息

相关问题

有相关的 GitHub 问题:

  1. Rule idea: Disallow accessing this.state within setState · Issue #943 · yannickcr/eslint-plugin-react.
  2. Rule Suggestion : setState function · Issue #1196 · yannickcr/eslint-plugin-react.
  3. Rule proposal: Require/Disallow passing an object to setState() if not using previous state · Issue #1836 · yannickcr/eslint-plugin-react.

请看一看。

«最近»问题

«相关问题»列表中的问题 #2 — Rule Suggestion : setState function · Issue #1196 · yannickcr/eslint-plugin-react — 似乎您的问题(请求)最接近或相同。

implementation-related 问题:Rule idea: Disallow accessing this.state within setState · Issue #943 · yannickcr/eslint-plugin-react

该功能似乎已部分实现。
部分原因是:

  1. 它只允许在 setState() 参数中使用 this.state:对象初始化器和函数。
  2. 虽然它仍然允许传递一个对象(不在其对象初始化器中使用this.state)作为setState()函数参数。例如:
    this.setState({quantity: 2});
    

请考虑向现有的“最接近”问题报告详细信息,以尝试re-open它或打开一个新问题。