Skip to content

QuizNot attempted

DOM ref inside an effect

What logs on mount?
function Input() {
const inputRef = useRef(null);
useEffect(() => {
console.log(inputRef.current.tagName);
}, []);
return <input ref={inputRef} />;
}
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • INPUT
  • React attaches refs during the commit phase, before running effects, so inputRef.current is the <input> node and tagName is 'INPUT'.
  • Not undefined/null: null is only seen during render, before commit.
  • Not 'throws': the node exists by the time effects run.