Answers for "react focus"

2

react focus

<input type="text" autoFocus />
Posted by: Guest on June-12-2020
0

react focus

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 ] 
}
Posted by: Guest on June-12-2020

Code answers related to "react focus"

Code answers related to "Javascript"

Browse Popular Code Answers by Language