React Interview Questions (60+ Deep Dive Q&A)
1. Core Architecture (Fiber)
1. What is React Fiber? (Visualized)
1. What is React Fiber? (Visualized)
- Render Phase (Async, Interruptible): Diffing, calculating changes. Is pure (no side effects).
- Commit Phase (Sync, Uninterruptible): DOM updates, Lifecycle methods.
2. Reconciliation (Diffing Algorithm)
2. Reconciliation (Diffing Algorithm)
- Different Component Types -> Different Trees (Destroy old, build new).
- Key Prop: Detecting moved elements in lists. Process: Compares Virtual DOM (Current vs WorkInProgress). Flags changes (Effect Tag).
3. Virtual DOM works how?
3. Virtual DOM works how?
render()creates V-DOM tree.- Diff with previous V-DOM.
- Calculate minimal batch of updates.
- Apply to Real DOM (
ReactDOM.render). Why?: Batching updates is faster than touching DOM 50 times.
4. React 18 Concurrency (Concurrent Features)
4. React 18 Concurrency (Concurrent Features)
useTransition: Mark state update as low priority (UI remains responsive).useDeferredValue: Debounce value (like user input).- Automatic Batching: Batches updates inside promises/timeouts now too.
5. Synthetic Events
5. Synthetic Events
2. Hooks Deep Dive
6. Why Hooks cannot be conditional?
6. Why Hooks cannot be conditional?
idx=0 (useState) -> idx=1 (useEffect) -> ...
If you put a hook in if, the order shifts on next render.
React loses track of which state belongs to which hook.7. `useEffect` vs `useLayoutEffect`
7. `useEffect` vs `useLayoutEffect`
- useEffect: Async. Runs after paint. Good for data fetch, subscriptions.
- useLayoutEffect: Sync. Runs after DOM mutation but before paint.
- Use: Measuring DOM layout (width/height) to prevent flickering.
8. `useMemo` vs `useCallback`
8. `useMemo` vs `useCallback`
- useMemo: Caches a Value.
const v = useMemo(() => compute(x), [x]). - useCallback: Caches a Function Reference.
const f = useCallback(() => {}, []).- Crucial for passing functions to
React.memochildren (prevents re-render).
- Crucial for passing functions to
9. `useRef` Internals
9. `useRef` Internals
{ current: initialValue }.
Mutating current does NOT trigger re-render.
Use: Accessing DOM elements, Storing Mutable variables (timers, prevProps) without render.10. `useReducer` vs `useState`
10. `useReducer` vs `useState`
useState is internally implemented using useReducer.
Use Reducer when:- Complex state logic (sub-values).
- Next state depends on previous state complexly.
- Testing logic in isolation (Reducer is pure function).
11. Custom Hooks Pattern
11. Custom Hooks Pattern
use.12. `useContext` + `useReducer` Pattern
12. `useContext` + `useReducer` Pattern
- Create Context.
- Provider holds
useReducerstate/dispatch. - Pass
dispatchdown. Issue: Context changes re-render ALL consumers.
3. Component Patterns
13. Higher Order Components (HOC)
13. Higher Order Components (HOC)
14. Render Props
14. Render Props
15. Compound Components
15. Compound Components
React.Children.map or Context.16. Controlled vs Uncontrolled
16. Controlled vs Uncontrolled
- Controlled: React manages state.
value={state}onChange={setState}. Single Source of Truth. - Uncontrolled: DOM manages state. Use
useRefto pull value.<input defaultValue="Hi" />.
17. Error Boundaries
17. Error Boundaries
componentDidCatch or getDerivedStateFromError.
Catches errors in Child Component Tree.
Displays Fallback UI.
Note: Cannot catch errors in Event Handlers or Async code (use Try/Catch there).18. Portals
18. Portals
ReactDOM.createPortal(child, container).
Use: Modals, Tooltips (z-index issues).
Event Bubbling: Events still bubble up the React Tree (Virtual), even if DOM is far away.4. Performance Optimization
19. `React.memo`
19. `React.memo`
React.memo(Comp, (prev, next) => areEqual).
Trap: Passing new object/function reference on every render kills Memo.20. Code Splitting (Lazy & Suspense)
20. Code Splitting (Lazy & Suspense)
21. Excessive Re-renders Fix
21. Excessive Re-renders Fix
- React DevTools Profiler (“Why did this render?”).
- Check context consumers being too broad.
- Check object references in
useEffectdependencies. - Move state down (Composition).
22. List Virtualization
22. List Virtualization
react-window / react-virtualized.
Render only visible slice + buffer.23. Key Prop anti-pattern
23. Key Prop anti-pattern
index as key.
If list is re-ordered or filtered, React reuses wrong components (state issues).
Always use Stable ID (item.id).24. Immutable State Why?
24. Immutable State Why?
prevProps === nextProps).
If you mutate object: obj.a = 1, the reference is same. React won’t see change.
Must create new object: setObj({ ...obj, a: 1 }).5. Ecosystem & Advanced
25. Redux vs Context
25. Redux vs Context
- Context: DI (Dependency Injection). Good for static/low-frequency global data (Theme, User). Re-renders ALL consumers.
- Redux/Zustand: State Management. Good for high-frequency updates. Selectors prevent unnecessary re-renders. Middleware (Thunk/Saga).
26. SSR (Server Side Rendering) vs CSR
26. SSR (Server Side Rendering) vs CSR
- CSR: Empty HTML. JS downloads -> Renders. Slow TTI. SEO Bad.
- SSR (Next.js): Server renders HTML -> Client Hydrates (Attaches listeners). Fast FCP. SEO Good.
- Hydration Error: Server HTML != Client HTML (e.g.,
Date.now(),windowusage).
27. React Server Components (RSC)
27. React Server Components (RSC)
28. Testing (RTL vs Enzyme)
28. Testing (RTL vs Enzyme)
- Enzyme: Implementation detail testing (“Does state ‘count’ equal 1?”). Fragile.
- RTL (React Testing Library): Behavior testing (“Do I see text ‘1’?”). Mimics user. Recommended.
29. Strict Mode effects
29. Strict Mode effects
- Renders components Twice (Detect impure renderers).
- Runs Effects Twice (Mount -> Unmount -> Mount). Checks cleanup logic.
- Warns deprecated API.
30. Prop Drilling Solutions
30. Prop Drilling Solutions
- Context.
- Composition: Pass components as props (
children,slot). - State Management Lib (Redux/Zustand).
6. Coding Scenarios
31. Implement a Counter (Hooks)
31. Implement a Counter (Hooks)
c => c+1 for safety.32. Fetch Data with useEffect
32. Fetch Data with useEffect
33. Implement `usePrevious` Hook
33. Implement `usePrevious` Hook
34. Implement `useDebounce` Hook
34. Implement `useDebounce` Hook
35. Optimize a heavy list (React.memo)
35. Optimize a heavy list (React.memo)
36. Force Update (Hack)
36. Force Update (Hack)
37. Modal with Portal
37. Modal with Portal
38. Focus Input on Mount
38. Focus Input on Mount
39. Context API basic implementation
39. Context API basic implementation
40. Catch 404 in Router
40. Catch 404 in Router
7. Edge Cases & Trivia
41. Can you use Hooks in Class Components?
41. Can you use Hooks in Class Components?
42. What happens if you call setState in render?
42. What happens if you call setState in render?
43. Is `setState` async?
43. Is `setState` async?
useEffect or the callback (in class components).44. `super(props)` purpose
44. `super(props)` purpose
Component constructor.
Enables this.props access in the constructor.45. Why does React require a Root element?
45. Why does React require a Root element?
<></> allows returning multiple siblings without adding DOM node.46. React vs Angular vs Vue
46. React vs Angular vs Vue
- React: Library. Virtual DOM. JSX. Flexible. One-way binding.
- Angular: Framework. Real DOM (mostly). Templates. Opiniated (DI, HTTP included). Two-way binding.
- Vue: Hybrid. Virtual DOM. Templates. Reactive mutable state.
47. Closures in Hooks (Stale Closures)
47. Closures in Hooks (Stale Closures)
useEffect without adding it to dependency array, you see the old value from the render closure where the effect was created.
Fix: Add to dependency array or use Functional State Update.48. `dangerouslySetInnerHTML`
48. `dangerouslySetInnerHTML`
innerHTML.
Named dangerously to warn about XSS attacks.
Required for rendering CMS content.49. PureComponent vs Component
49. PureComponent vs Component
PureComponent implements shouldComponentUpdate with shallow prop comparison automatically.
Component re-renders always unless manually stopped.50. Flux Architecture pattern
50. Flux Architecture pattern
8. React 19 & Future (Bonus)
51. React Compiler (Forget)
51. React Compiler (Forget)
useMemo / useCallback.
Compiler detects what needs caching.52. `use` Hook
52. `use` Hook
const data = use(fetchData()).53. Actions (Server Functions)
53. Actions (Server Functions)
<form action={serverAction} />.
Seamless RPC. Handle form submission on server.
Manages pending state automatically.54. `useOptimistic`
54. `useOptimistic`
55. Document Metadata
55. Document Metadata
<title> and <meta> tags inside components.
Hoisted to <head>. Replaces react-helmet.56. Asset Loading
56. Asset Loading
57. Web Components support
57. Web Components support
58. Ref as a Prop
58. Ref as a Prop
forwardRef.
Just pass ref as a normal prop to Function Components.59. `<Context>` instead of `<Context.Provider>`
59. `<Context>` instead of `<Context.Provider>`
<ThemeContext value="dark"> works directly.60. Directives ('use client', 'use server')
60. Directives ('use client', 'use server')
'use server': Marks function as Server Action or component as Server Component.'use client': Opts back into Client Side Rendering (Hooks, Event Listeners).