focus on element javascript react code example
Example 1: react focus textarea
const focusDiv = useRef();
useEffect(() => {
if(focusDiv.current) focusDiv.current.focus();
}, [focusDiv]);
return (
<div ref={focusDiv}></div>
);
Example 2: react focus
<input type="text" autoFocus />