I really need your help! I've written two versions of react functions. One with the spread operator and the other without and only the version without is working.
Working version:
onAddBook() {
var updatedBooks = this.state.books;
var finalBook = {
title: this.state.title
};
updatedBooks.push(finalBooks);
this.setState({
books: updatedBooks
});
}
Not working:
var finalBook = {
title: this.state.title
}
this.setState({
books: [...this.state.books, finalBook]
});