0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

typescript での React refの書き方 備忘録

Posted at

Typescriptでの React refの書き方

anyで手を抜きがちなのでメモ

参考リンク: any型で諦めない React.EventCallback


import * as React from 'react'

export class Test extends React.Component<Props>{
  // refs
  private selectElement: HTMLSelectElement; // select Element
  private inputElement: HTMLInputElement; // input Element
  render(){
    return(
      <div>
        <input
          type="text"
          ref={input => this.inputElement = input}
        />
        <select
          name={name}
          value={value}
          onChange={this.onChange}
          ref={input => this.selectElement = input}
         >
          {children}
        </select>
      </div>

    )
  }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?