简体   繁体   中英

Flow type of React's ref

What type returns React.createRef() ?

I have tried React.Ref<HTMLSelectElement> , React$Ref<HTMLSelectElement> , React$Ref<typeof HTMLSelectElement> and a few more, but nothing works. It is either missing, or wrong type.

Does Flow even support refs created via createRef ?

Judging by the definition of React.createRef , you should be able to do something like this:

class MyComponent extends React.Component<{}> {
  ref: { current: null | HTMLDivElement };

  constructor(props: any) {
    super(props);
    this.ref = React.createRef();
  }

  render() {
    return <input ref={this.ref} />;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM