Ref: Adding a Ref to a Class Component

Adding a Ref to a Class Component

class AutoFocusTextInput extends React.Component {
  constructor(props) {
    super(props);
    this.textInput = React.createRef();
  }

  componentDidMount() {
    this.textInput.current.focusTextInput();
  }

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

class CustomTextInput extends React.Component {
  // ...
}

Related concepts

Adding a Ref to a Class Component

Ref: Adding a Ref to a Class Component — Structure map

Clickable & Draggable!

Ref: Adding a Ref to a Class Component — Related pages: