I my react class component I tried it this way. But as soon as it renders the alert popup keeps coming all the time without any button click.
onHandleOnClick(data, e) {
console.log(data);
alert("got it" + data);
}
renderRating(){
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
return arr.map((val) => {
return (
<button
onClick={this.onHandleOnClick(val)}
>
{val}
</button>
);
});
};
render() {
return (
<div>
{this.renderRating()}
</div>
)
}
I am new in React. How do I do it?
onClick={(e) => this.onHandleOnClick(val, e)}