UseRef — A Side Note to the Official Doc

The following can be read as a side note to the official React Doc

meme reference


function TextInputWithFocusButton() {
const inputEl = useRef(null);
const onButtonClick = () => {
// `current` points to the mounted text input element
return (
<input ref={inputEl} type="text" />
<button onClick={onButtonClick}>Focus the input</button>
example(1): useRef inside useEffect
example(2) useRef called in event handler
example(2) useRef can hold a function