Filter by the role you are applying for, open a question, and practise explaining the answer out loud. Mark it practised when you can.
Why they ask this: Most React bugs (infinite loops, stale data, memory leaks) come from misusing useEffect.
Answer
useEffect(effect, deps) runs effect after render:
[]: runs once after the first render (mount).[a, b]: runs after the first render and again whenever a or b changes (compared with Object.is).The function you return is the cleanup. It runs before the effect runs again and when the component unmounts. Use it to remove listeners, clear timers and cancel requests.
useEffect(() => {
const controller = new AbortController();
fetch(`/api/jobs?q=${query}`, { signal: controller.signal })
.
Why they ask this: Forms are in every app; this shows how you handle user input and validation.
Answer
Include every value from the component that the effect uses in the array. Missing dependencies cause stale values.
value comes from state and every change goes through onChange.ref or from the form data on submit.// Controlled
const [email, setEmail] = useState('');
<input value={email} onChange={(e) => setEmail(e.target.value)} />
// Uncontrolled
const inputRef = useRef(null);
<input ref={inputRef} defaultValue="" />
// later: inputRef.current.valueChoose controlled inputs for instant validation, formatting or conditional UI. Uncontrolled inputs are simpler for basic forms and file inputs (<input type="file"> is always uncontrolled). Form libraries such as React Hook Form mostly use uncontrolled inputs for performance.