Skip to content

Instantly share code, notes, and snippets.

@mfrancois3k
Forked from MinthangML/useRefInFuncCompo.js
Created March 21, 2022 17:06
Show Gist options
  • Save mfrancois3k/8a8300dac2dc89d7b84c73722cb8b91a to your computer and use it in GitHub Desktop.
Save mfrancois3k/8a8300dac2dc89d7b84c73722cb8b91a to your computer and use it in GitHub Desktop.
useRef in functional component
import React, { useRef } from "react";
const CustomTextInput = () => {
const textInput = useRef();
focusTextInput = () => textInput.current.focus();
return (
<>
<input type="text" ref={textInput} />
<button onClick={focusTextInput}>Focus the text input</button>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment