Answers for "how to get value from onClick handler in react"

0

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`
  });
};
Posted by: Guest on August-16-2021

Code answers related to "how to get value from onClick handler in react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language