Родитель с функцией удаления:
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
items: [],
currentItem: {
text: '',
key: '',
}
}
this.addItem = this.addItem.bind(this)
this.deleteItem = this.addItem.bind(this)
this.handleInput = this.handleInput.bind(this)
}
deleteItem(key) {
const filteredItems= this.state.items.filter(item => item.key !== key)
this.setState({
items: filteredItems
})
}
render() {
return (
<div className="App">
<header>
<form id="goalForm">
<input type="text" placeholder="Enter your main goal"
value={ this.state.currentItem.text }
onChange={ this.handleInput }>
</input>
<button type="submit" onClick={ this.addItem }>Add</button>
</form>
</header>
<ListItems items = { this.state.items }
deleteItem = { this.deleteItem }
/>
</div>
)
Ну и сами перечисления "задач":
function ListItems(props) {
const items = props.items
const listItems = items.map(item => {
return (
<div className="list" key = { item.key }>
<div className="goal">
<p>{ item.text }</p>
<span>
<FontAwesomeIcon className="faicons" icon={ faTrash }
onClick={() => {
props.deleteItem(item.key)
}
}
/>
</span>
</div>
</div>
)
})
return (
<div>{ listItems }</div>
)
}
Получаю ошибку, типо такого: