useFocus

If you just want to focus on an element when it mounts:


RESETRUNFULL
<input type="text" autoFocus />

To control focus dynamically:


RESETRUNFULL
const FocusDemo = () => {
    const [inputRef, setInputFocus] = useFocus()
    return (
        <>
             <button onClick={setInputFocus} >
               Focus
            </button>
            <input ref={inputRef} />
        </>
    )}const useFocus = () => {
    const htmlElRef = useRef(null)
    const setFocus = () => {htmlElRef.current &&
  htmlElRef.current.focus()}
    return [ htmlElRef, setFocus ] }