Remove item from array in React

后端 未结 8 839
醉酒成梦
醉酒成梦 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:35

      removeItem(item) {
          const item = getItem(this.state.list, item.id) // Method to get item in list through comparison (IE: find some item with item.id), it has to return ITEM and INDEX in array
          const newlist = [].concat(list) // Clone array with concat or slice(0)
          newlist.splice(item.index, 1);
          this.setState({list: newlist});       
        }
      

    提交回复
    热议问题