矢印関数がおかしい

3614 ワード

class Test extends Component {

  onClickBtn = (text) => {
   ... 
  }
   
  render() {
	return (
      <button onClick={() => this.onClickBtn("hello")}></button>
    )
  }
}
これをもう少し簡単にして、次のように変えてもいいです.onClickBtnとonClick={.}部分をよく見てみましょう(high order function)
class Test extends Component {

  onClickBtn = (text) => () => {
   ... 
  }
   
  render() {
	return (
      <button onClick={this.onClickBtn("hello")}></button>
    )
  }
}