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
import React, { Component } from 'react';
import './Todo.css';
class Todo extends Component {
constructor(props) {
super(props);
this.state = {
list: [],
text: ''
}
this.textChange = this.textChange.bind(this);
this.addToList = this.addToList.bind(this);
}
textChange(e) {
this.setState({
text: e.target.value
})
}
addToList() {
this.setState(prevState => ({
list: prevState.list.concat(this.state.text),
text: ''
}))
}
removeItem(index) {
let newList = this.state.list.splice(index,1);
this.setState({list:newList})
}
render() {
return(
My Todo List
Add item
this.textChange(e)}/>
{this.state.list.map((x,y) => {
return - {x}
})}
)
}
}
export default Todo;