// src/App.jsx
import { useEffect, useRef } from "react";
function AutoFocusInput() {
const inputRef = useRef(null);
useEffect(() => {
inputRef.current.focus();
}, []);
return ;
}
function App() {
return ;
}
export default App;
/*
Notes:
- The empty dependency array means the effect runs once, right after
the first render — by that point inputRef.current is guaranteed to
already be the real DOM node.
- Calling .focus() directly on inputRef.current works exactly like
calling it on any DOM element selected with plain JavaScript.
*/