0

https://reactjs.org/docs/faq-functions.html#example-passing-params-using-data-attributes .

Essentially, it is an optimization of arrow function

  <li key={letter} onClick={() => this.handleClick(letter)}>              
    {letter}
  </li>

to the following to avoid rerendering

  <li key={letter} data-letter={letter} onClick={this.handleClick}>
    {letter}
  </li>


  handleClick(e) {
    this.setState({
      justClicked: e.target.dataset.letter
    });
  }

I find it doesn't work for react-native-web, e.target.dataset is empty.
Is this expected?

eugene
  • 39,839
  • 68
  • 255
  • 489

1 Answers1

0

i think you just need to change the declaration of your function to something like this:

handleClick = (e) => {
  this.setState({
    justClicked: e.target.dataset.letter
  });
}
tjadli
  • 790
  • 6
  • 16