Skip to content

Instantly share code, notes, and snippets.

@cecigarcia
Created June 27, 2019 09:06
Show Gist options
  • Save cecigarcia/66865053c5c92d15d190558baffd3a97 to your computer and use it in GitHub Desktop.
Save cecigarcia/66865053c5c92d15d190558baffd3a97 to your computer and use it in GitHub Desktop.
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