React Top-Level API: React.createRef

React.createRef

class MyComponent extends React.Component {
  constructor(props) {
    super(props);

    this.inputRef = React.createRef();
  }

  render() {
    return <input type="text" ref={this.inputRef} />;
  }

  componentDidMount() {
    this.inputRef.current.focus();
  }
}

Creates a ref that can be attached to React elements via the ref attribute.

Related concepts

React Top-Level API: React.createRef — Structure map

Clickable & Draggable!

React Top-Level API: React.createRef — Related pages: