You need to use
hook to set focus on input field during page load time for functional component.useEffect
import React, { useEffect, useRef } from "react";const App = () => {const inputElRef = useRef(null);useEffect(() => {inputElRef.current.focus();}, []);return (<div><input defaultValue={"Won't focus"} /><input ref={inputElRef} defaultValue={"Will focus"} /></div>);};ReactDOM.render(<App />, document.getElementById("app"));
See Class
You can do it by creating _ref_ for `input` element and using it in `componentDidMount()`:
class App extends React.Component {componentDidMount() {this.nameInput.focus();}render() {return (<div><input defaultValue={"Won't focus"} /><inputref={(input) => (this.nameInput = input)}defaultValue={"Will focus"}/></div>);}}ReactDOM.render(<App />, document.getElementById("app"));