Focus An Input With useRef Hook
import React, { useRef } from 'react';
const MyComponent = () => {
const inputRef = useRef(null);
const focusInput = () => {
inputRef.current.focus();
}
return (
<div>
<input
ref={inputRef}
type="text"
value=""
{...otherProps}
/>
<button onClick={focusInput}>Edit Input</button>
</div>
);
}Last updated