focus an inpout react code example
Example 1: How to set focus on an input field after rendering?
componentDidMount(){
this.nameInput.focus();
}
Example 2: react focus textarea
const focusDiv = useRef();
useEffect(() => {
if(focusDiv.current) focusDiv.current.focus();
}, [focusDiv]);
return (
<div ref={focusDiv}></div>
);