最終更新:2022-12-16 (金) 04:24:17 (500d)  

React/コールバックRef
Top / React / コールバックRef

https://ja.reactjs.org/docs/refs-and-the-dom.html#callback-refs

  • refに関数を指定することができる
  constructor(props) {
    super(props);

    this.textInput = null;

    this.setTextInputRef = element => {
      this.textInput = element;
    };


 <input
          type="text"
          ref={this.setTextInputRef}
        />