ESLint必须使用解构状态分配 [英] ESLint Must use destructuring state assignment

查看:689
本文介绍了ESLint必须使用解构状态分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下行 this.state.items.map(item =>(

错误是必须使用解构状态分配

{
            this.state.items.map(item => (
              <div key={item}>
                {
                item.links.map(thing => (
                  <NavLink
                    key={thing.link.id}
                    exact
                    to={thing.link.url}
                  >
                    {thing.link.text}
                  </NavLink>
                ))
                }
              </div>
            ))
          }

我正在使用 eslint-config-airbnb

I am using "eslint-config-airbnb"

,如果有关联,这就是我的componentDidMount函数

Also, this is my componentDidMount function if this is related

componentDidMount() {
  fetch('./data/data_arr.js')
  .then(results => results.json())
  .then(results => this.setState({ items: results }));
}

任何帮助尝试并理解这一点的方法都将非常有用。谢谢

Any help to try and understand this would be great. thank you

推荐答案

即是:


强制一致使用道具,状态,
和上下文(反应/解构分配)的解构分配

Enforce consistent usage of destructuring assignment of props, state, and context (react/destructuring-assignment)

更多有关详细信息,请参见: destructuring-assignment

More details are available here: destructuring-assignment

为了使警告/错误消失,您可以这样操作:

In order to make that warning/error disappear, you could do like this:

      ...
      const { items }= this.state;
      ...
      {
        items.map(item => (
          <div key={item}>
            {
            item.links.map(thing => (
              <NavLink
                key={thing.link.id}
                exact
                to={thing.link.url}
              >
                {thing.link.text}
              </NavLink>
            ))
            }
          </div>
        ))
      }

这篇关于ESLint必须使用解构状态分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆