I want to make a boolean true on the click of a button, but it shows "undefined" on console.log
export default class productdetail extends Component {
constructor(props){
super(props);
this.state = {
showCartMessage:false ,
}
this.handleCartListener = this.handleCartListener.bind(this);
}
handleCartListener(){
this.setState({ showCartMessage: true });
console.log(this.showCartMessage)
}
actionForProducts(product) {
return(
<div className="">
<button className="add_cart btn rounded-pill w-100 " onClick=
{this.handleCartListener}>
Add To Cart
</button>
</div>
)
}
render(){
return(
<div className="p-3 h-100 ">
{this.actionForProducts(this.props.productdetail)}
</div>
)
}
}
How to resolve this? I tried so many times but it gives the same response.