how to get value from onclick handler in react

Solutions on MaxInterview for how to get value from onclick handler in react by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to get value from onclick handler in react"
Lia
09 Sep 2020
1// Render a block of three buttons
2[1, 2, 3].map(buttonId => (
3  // Pass a parameter in 'value' attribute
4  <button
5    key={buttonId}
6    value={buttonId}
7    onClick={this.handleButtonClicked}
8  >
9    button {buttonId}
10  </button>
11));
12...
13handleButtonClicked = ev => {
14  this.setState({
15    // Retrieve a passed parameter 'value' attribute
16    message: `Button ${ev.currentTarget.value} clicked`
17  });
18};
19