How to focus an input element on page load?

You can do it by creating ref for input element and using it in componentDidMount():

class App extends React.Component {
componentDidMount() {
render() {
return (
<input defaultValue={"Won't focus"} />
<input ref={(input) => (this.nameInput = input)} defaultValue={'Will focus'} />
ReactDOM.render(<App />, document.getElementById('app'));

Author of content
Edit this page

Made by Michael Sakhniuk