A
A
Anubis2018-05-27 11:43:12
React
Anubis, 2018-05-27 11:43:12

[react + flow] What type to specify for a variable created by React.createRef()?

// @flow

import * as React from 'react';

class MyCrap extends React.Component<{}> {
  myRef: any = React.createRef();
  
  render() {
    return <div ref={this.myRef}>Hello</div>;
  }
}

Obviously, instead of any, you can specify a more precise type. Unfortunately, so far I've only come up with something like this:
// @flow

import * as React from 'react';

type Ref = {
    current: any
}

class MyCrap extends React.Component<{}> {
  myRef: Ref = React.createRef();
  
  render() {
    return <div ref={this.myRef}>Hello</div>;
  }
}

I'm sure for current instead of any you can specify the type more precisely. But I haven't figured out which one yet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2018-05-27
@Anubis

According to the doc , it should be
?HTMLDivElement

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question