Skip to content

Instantly share code, notes, and snippets.

@MinthangML
Last active December 21, 2020 04:40
Show Gist options
  • Save MinthangML/33e5070136a31c56488efb7e72858554 to your computer and use it in GitHub Desktop.
Save MinthangML/33e5070136a31c56488efb7e72858554 to your computer and use it in GitHub Desktop.
useRef in class component
import React, { Component, createRef } from "react";
class CustomTextInput extends Component {
textInput = createRef();
focusTextInput = () => this.textInput.current.focus();
render() {
return (
<>
<input type="text" ref={this.textInput} />
<button onClick={this.focusTextInput}>Focus the text input</button>
</>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment