ESLint Must use destructuring state assignment

后端 未结 1 613
灰色年华
灰色年华 2020-12-07 00:09

I am getting ESlint error for the following line this.state.items.map(item => (

The error is Must use destructuring state assignment

相关标签:
1条回答
  • 2020-12-07 00:53

    That's called:

    Enforce consistent usage of destructuring assignment of props, state, and context (react/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>
            ))
          }
    
    0 讨论(0)
提交回复
热议问题