how to get value from onClick handler in react
// Render a block of three buttons
[1, 2, 3].map(buttonId => (
// Pass a parameter in 'value' attribute
<button
key={buttonId}
value={buttonId}
onClick={this.handleButtonClicked}
>
button {buttonId}
</button>
));
...
handleButtonClicked = ev => {
this.setState({
// Retrieve a passed parameter 'value' attribute
message: `Button ${ev.currentTarget.value} clicked`
});
};