Is it possible to set the properties from mapStateToProps and use setState to change the state and save that information to my database? The data is being returned from google books api and I want to save a small portion of the data.
My state:
state = {
title: '',
subtitle: '',
authors: '',
description: '',
thumbnail: '',
buyLink: ''
};
Function to setState and save to database
let { book } = this.props.book;
let bookInfo;
if (book !== null) {
const onSave = (e) => {
e.preventDefault();
let savedData = this.setState({
title: book.volumeInfo.title,
subtitle: book.volumeInfo.subtitle,
authors: book.volumeInfo.authors,
description: book.volumeInfo.description,
thumbnail: book.volumeInfo.imageLinks.thumbnail,
buyLink: book.saleInfo.buyLink
});
console.log(savedData);
};
// this.props.saveBook(savedData, this.props.history);
bookInfo = <BookInfo book={book} onClick={onSave} />;
}
savedData returns undefined
const mapStateToProps = (state) => ({
book: state.books
});