class Product extends Component {
// 1st code
onAddToCart() {
console.log('Buy Successfully');
}
<a className="btn btn-primary" onClick={this.onAddToCard}>Buy Now</a>
// 2nd Code
onAddToCart(text) {
console.log(text);
}
<a className="btn btn-primary" onClick={this.onAddToCard('Buy Successfully')}>Buy Now</a>
The first one run successfully and the second one is failed. As my understand, when react renders of the second one, it will invoke onAddToCart immediately but the first one doesn't do this. So, I don't understand how they work.