I'm using prevProps and prevState in my componentDidUpdate method, but it says the variable book isn't defined. However, I've tried different ways of defining it that don't work. I've also seen examples where this is unnecessary. Can someone please take a look at this and let me know what I might be missing?
class Dashboard extends Component {
state = {
// book: this.props.book,
book: '',
info: this.props.info,
error: '',
}
// constructor(props) {
// super(props);
// this.state = {
// book: '',
// info: '',
// error: '',
// }
// }
async componentDidUpdate(prevProps, prevState) {
// const book = this.props.book;
// console.log(`book: ${book}`);
if (prevProps.book !== this.props.book) {
try{
const data = await GoogleAPI.getBook(book);
if (data.length > 0){
this.setState({
book: book,
info: data,
})
}
else {
this.setState({error: 'Book Not Found'})
}
}
catch {
// this.props.setModal('Offline');
}
}
// console.log(`book check state: ${book}`);
console.log(`prevProps: ${prevProps.book}`);
//Checking for book state here
console.log(`book state: ${this.state.book}`);
}