Interview Q&A / React

INTERVIEW Q&A · 58 QUESTIONS

React interview questions

Rendering, state, hooks, keys and effects, explained with small examples.

  1. How do you focus an input automatically when a component mounts?

    Attach a ref to the input with ref={inputRef}, then call inputRef.current.focus() inside a useEffect with an empty dependency array. The ref is filled only after the element is in the DOM.

    BeginnerQuick answer1 min read