Q1
Why does updating an object property directly (user.name = 'A'; setUser(user)) fail to re-render a React component?
React compares state via Object.is(prev, next). Since the mutated user reference is still identical to prev, React assumes nothing changed and bails out of rendering. Always spread a new reference ({ ...user, name: 'A' }).
Q2
When is useMemo or React.memo actually harmful to performance?
Memoizing trivial primitives or un-memoized inline prop callbacks adds comparison and memory allocation overhead on *every* render while still failing shallow equality checks.
Q3
What is the critical difference between useEffect and useLayoutEffect when measuring DOM node dimensions?
useEffect runs *after* browser paint (causing visible flicker if positioning tooltips/modals). useLayoutEffect runs synchronously *after* DOM mutations but *before* paint, preventing layout jumps.
Q4
Why can React Context cause unexpected full-subtree re-renders—and how do you split Context cleanly?
Passing a fresh { user, setUser } object into <Ctx.Provider value={{ user, setUser }}> triggers every useContext consumer whenever the provider re-renders. Memoize the value object or separate state and dispatch contexts.
Q5
What happens if you call Hooks conditionally (if (isOpen) useEffect(...))?
React stores hook state in a fixed per-component linked array indexed by call order. Skipping a hook shifts every subsequent hook slot, causing state mismatch crashes.
Q6
How do Controlled vs Uncontrolled inputs behave when resetting a large multi-field form?
Controlled inputs mirror React state (value + onChange) for live validation, whereas uncontrolled refs (defaultValue) rely on DOM state. Mixing value={undefined} then 'text' throws React controlled/uncontrolled warnings.
Q7
Why does useRef NOT trigger a component re-render when ref.current changes?
useRef returns a persistent mutable box ({ current }) outside React's state scheduler—making it ideal for DOM elements, timer IDs, and previous-value tracking without render overhead.
Q8
What causes React hydration mismatch warnings if SSR renders Date.now() or window.innerWidth directly?
Server HTML differs from the browser's first client render pass, forcing React to discard SSR nodes or warn. Gate browser-only values inside useEffect so initial hydration matches 100%.
Q9
How does React Error Boundary work—and which errors does it NOT catch automatically?
Error Boundaries catch render, lifecycle, and constructor errors in child trees, but they do NOT catch errors inside async callbacks, setTimeout, or onClick event handlers (use try/catch there).
Q10
Why should heavy derived totals (e.g., cart.reduce(...)) be computed inline during render rather than duplicated into separate useState + useEffect?
Mirroring derived values in extra useState adds stale intermediate render frames and synchronization bugs. Compute derived values directly during render (memoized with useMemo only if expensive).