Remove item from array in React

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

      I think you should pass the index of the item to your removeItem function. Like so:

      removeItem(index) {
        const list = this.state.list;
      
        list.splice(index, 1);
        this.setState({ list });
      }
      
      render() {
        return(
          

      My Todo List

      Add item

      this.textChange(e)}/>
        { this.state.list.map((text, i) => { return (
      • {text}
      • ); })}
      ) }

    提交回复
    热议问题