Remove item from array in React

后端 未结 8 814
醉酒成梦
醉酒成梦 2021-01-03 12:45

I have problem with removeItem function (it should remove current

  • that button is nested in, and item from array on this.state.list), no code currentl
  • 8条回答
    •  小鲜肉
      小鲜肉 (楼主)
      2021-01-03 13:30

      in my solution eg:

      const remove = (i) => {
              const arr = data.filter((item) => item.name !== i);
              setData(arr);
          };
      

      I filtered the items that are not removed and set again the state

    提交回复
    热议问题