Set 4: Super Hard / Expert Level (with Answers)
1. What are the phases of the React component lifecycle?
π For class components:
-
Mounting (constructor β render β componentDidMount)
-
Updating (shouldComponentUpdate β render β componentDidUpdate)
-
Unmounting (componentWillUnmount)
-
Error Handling (componentDidCatch)
Hooks manage lifecycle differently via useEffect.
2. How does React decide when to re-render a component?
π If props or state change (with different reference/value) and depending on shouldComponentUpdate (class) or React.memo (functional).
3. What is the difference between Context vs Redux vs Recoil?
π
-
Context: Good for simple global states like theme, auth.
-
Redux: Centralized store, middleware support (e.g., async actions, complex apps).
-
Recoil: Atom-based fine-grained state management β better performance for huge apps with minimal re-renders.
4. What are React Server Components (RSC)?
π New experimental feature where components are rendered fully on the server, never sent to the client as JS β smaller bundle size, faster apps.
5. Explain the Virtual DOM diffing algorithm (Reactβs reconciliation process).
π
-
Compares old vs new virtual DOM tree.
-
If nodes are of different types β destroy old node and build new.
-
If types match β do a deep diff on attributes and recursively on children.
6. How can React optimize performance for deeply nested components?
π
-
React.memo, -
useMemo,useCallback, -
windowing(react-window), -
Avoid unnecessary context updates,
-
Split huge trees into smaller pieces.
7. What is the difference between debounce and throttle? Where would you use them in React?
π
-
Debounce: Wait a certain time after last call (ex: search input).
-
Throttle: Limit execution to once every interval (ex: scroll event).
Uselodash.debounceandlodash.throttlefor these.
8. How does React handle asynchronous rendering?
π With Concurrent Features β React can pause, interrupt, abort, or reuse work.
9. How would you cancel an API request in React if the component unmounts?
π
-
Using
AbortController:
10. What is a Suspense List?
π A way to coordinate multiple Suspense components and control their reveal order to avoid ugly “pop-in” content.
11. What is hydration mismatch in SSR (Server-Side Rendering)?
π When server-rendered HTML does not match the client-side React tree β React throws warnings.
12. How does React batch multiple setState calls?
π
-
In event handlers, React batches multiple state updates into a single render.
-
In async code (like setTimeout), you must wrap updates inside
unstable_batchedUpdates()or manually batch.
13. What is Priority-based scheduling in React?
π React assigns priorities to different updates (e.g., urgent for typing vs non-urgent for background updates) and schedules rendering accordingly (based on expiration time).
14. Explain the working of React.lazy and dynamic imports.
π
-
React.lazyloads components on-demand (dynamic imports under the hood). -
Bundles the code separately (chunk splitting).
15. How do Suspense and Error Boundaries differ?
π
-
Suspense handles loading asynchronous code/resources.
-
Error Boundary catches JavaScript errors in children components.
16. How to optimize React apps for SEO?
π
-
Use Server-Side Rendering (Next.js)
-
Use correct
<title>,<meta>tags -
Pre-render critical pages.
17. What is the key propβs role in React internal architecture?
π
-
Key tells React how to efficiently update children lists β
Without key β destroy and recreate DOM nodes unnecessarily.
18. Explain the concept of stale closures in React hooks.
π
-
When closures inside
useEffector event handlers access outdated states/props because they captured old values at the time of definition.
19. How do you implement Infinite Scrolling in React?
π
-
Use Intersection Observer API or listen to scroll events β fetch more items when reaching bottom.
20. What is the difference between prop drilling vs state lifting?
π
-
Prop drilling: passing props down multiple layers unnecessarily.
-
State lifting: moving shared state up to a common parent to manage flow properly.
21. What is React Hooks rules? (Rules of Hooks)
π
-
Only call hooks at the top level.
-
Only call hooks inside React functions (components or custom hooks).
22. How does the Suspense fallback mechanism work internally?
π
-
When React encounters a Suspense boundary and the content inside isn’t ready β it immediately shows the fallback until the child resolves.
23. How can React handle concurrent user actions (like typing + fetching)?
π
-
With
useTransition,startTransition()to mark updates as non-urgent β keeps typing smooth.
24. What is the Profiler API in React?
π
-
React Profiler measures performance β how much time a component takes to render, re-render, and when.
25. What is the difference between SSR, SSG, CSR, and ISR?
π
-
SSR: Server Side Rendering (dynamic) β Next.js.
-
SSG: Static Site Generation (pre-rendered at build time).
-
CSR: Client Side Rendering (browser renders everything).
-
ISR: Incremental Static Regeneration (Next.js can rebuild static pages on-demand).
