{jsonbody.com}

Top 200 React.js Interview Questions and Answers

Master your frontend developer interview with our ultimate collection of top 200 React.js interview questions, hooks, advanced concepts, and expert answers.

Q1. What is React?

React is an open-source front-end JavaScript library developed by Meta (Facebook) for building user interfaces based on UI components, emphasizing reusable and declarative code.

Q2. What are the main features of React?

Key features include JSX, Virtual DOM, One-Way Data Binding, Component-Based Architecture, High Performance, and support for Server-Side Rendering.

Q3. What is JSX?

JSX (JavaScript XML) is a syntax extension for JavaScript that allows you to write HTML-like structures directly inside JavaScript code, which gets compiled to React.createElement() calls.

Q4. What is the Virtual DOM?

The Virtual DOM is a lightweight lightweight in-memory representation of the real DOM. React uses it to compute minimal diffs and update only the changed elements in the real DOM, boosting performance.

Q5. How does the React reconciliation process work?

Reconciliation is the process through which React updates the DOM. When component state changes, React creates a new Virtual DOM tree, compares it with the previous snapshot (diffing algorithm), and applies the minimal set of changes to the real DOM.

Q6. What is the difference between Real DOM and Virtual DOM?

Real DOM updates slowly and forces reflows/repaints of entire elements, whereas Virtual DOM updates quickly in memory before efficient batch-updating to the Real DOM.

Q7. What are components in React?

Components are independent, reusable building blocks of a React application. They split UI into smaller, isolated pieces and can be functional or class-based.

Q8. What is the difference between Functional and Class components?

Functional components are simple JavaScript functions that accept props and return JSX (now enhanced with Hooks for state). Class components are ES6 classes that extend React.Component, manage their own state via this.state, and use lifecycle methods.

Q9. What are props in React?

Props (short for properties) are read-only inputs passed from parent to child components to configure or customize their rendering.

Q10. What is State in React?

State is an internal, mutable object managed within a component that holds data subject to change over time, triggering re-renders when updated.

Q11. What is the difference between Props and State?

Props are passed down from parent components and are immutable to the receiver. State is managed internally within the component and is mutable via state setters.

Q12. What are SyntheticEvents in React?

SyntheticEvents are React's cross-browser wrapper around the browser's native events, ensuring consistent event behavior across different browsers and improving performance through event pooling.

Q13. Why should you not update state directly?

Updating state directly (e.g., this.state.count = 2) does not trigger a React re-render, leading to UI desynchronization. Always use setState() or state setter functions.

Q14. What is conditional rendering in React?

Rendering different UI elements or components based on specific conditions using JavaScript operators like if/else, ternary operator (? :), or logical AND (&&).

Q15. Why do we need keys in React lists?

Keys help React identify which items have changed, been added, or removed. They provide unique stable identities to list items, optimizing reconciliation performance.

Q16. Why should index not be used as a key in lists?

Using array indices as keys causes bugs and performance issues if items get reordered, filtered, or deleted, because React relies on stable identities rather than positional indices.

Q17. What are Higher-Order Components (HOC)?

An HOC is a advanced pattern in React where a function takes a component and returns a new enhanced component, used for code reuse and cross-cutting concerns.

Q18. What are Pure Components?

Pure Components (created via React.PureComponent or React.memo) automatically implement shouldComponentUpdate with a shallow prop and state comparison to prevent unnecessary re-renders.

Q19. What is React Fragment?

React Fragments (<></> or <React.Fragment>) let you group a list of children without adding extra nodes to the DOM tree.

Q20. What are Controlled Components?

Components where form data is handled by React component state, making React the 'single source of truth'.

Q21. What are Uncontrolled Components?

Components where form data is handled directly by the DOM itself, accessed using refs rather than component state.

Q22. What are Refs in React?

Refs provide a way to access DOM nodes or React elements created in the render method directly, typically using useRef() or createRef().

Q23. When should you use Refs?

For managing focus/text selection, triggering imperative animations, integrating with third-party DOM libraries, or capturing media elements.

Q24. What is PropTypes?

A type-checking library for React props that helps catch runtime bugs by validating data types passed to components during development.

Q25. What is strict mode in React?

React.StrictMode is a tool for highlighting potential problems in an application, activating additional checks and warnings in development mode.

Q26. What are React Hooks?

Hooks are functions that let functional components hook into React state, lifecycle features, and context without writing class components.

Q27. What rules must be followed when using Hooks?

1. Only call hooks at the top level (never inside loops, conditions, or nested functions). 2. Only call hooks from React functional components or custom hooks.

Q28. Explain useState hook.

useState returns a stateful value and a function to update it, taking an initial state argument.

Q29. Explain useEffect hook.

useEffect lets you perform side effects (data fetching, subscriptions, DOM manipulation) in functional components, replacing lifecycle methods like componentDidMount and componentDidUpdate.

Q30. What is the cleanup function in useEffect?

A function returned inside useEffect that executes when the component unmounts or before running the effect again, used to clear timers, subscriptions, or event listeners.

Q31. What is the dependency array in useEffect?

An array parameter determining when the effect runs. Empty array [] runs once on mount; omitted runs on every render; variables array runs when specified variables change.

Q32. What is useContext hook?

useContext accepts a Context object and returns the current context value, enabling prop-drilling avoidance across component trees.

Q33. What is useReducer hook?

An alternative to useState for managing complex state logic involving multiple sub-values or state transitions driven by actions, inspired by Redux.

Q34. What is useCallback hook?

A hook that caches (memoizes) a callback function definition between renders, preventing unnecessary child re-renders when passed as props.

Q35. What is useMemo hook?

A hook that memoizes the computed return value of an expensive function calculation, recalculating only when dependencies change.

Q36. What is the difference between useCallback and useMemo?

useCallback memoizes a function instance, whereas useMemo memoizes the result returned by a function execution.

Q37. What is useRef hook?

A hook returning a mutable .current object whose value persists across component renders without triggering re-renders when modified.

Q38. What is useLayoutEffect hook?

Similar to useEffect, but fires synchronously *after* all DOM mutations, useful for reading DOM layout measurements before browser paint.

Q39. What is useId hook?

A hook for generating unique IDs across server and client renders, avoiding hydration mismatch errors on form elements.

Q40. What is useTransition hook?

A hook that lets you update state without blocking the UI, marking state transitions as non-urgent background tasks.

Q41. What is useDeferredValue hook?

A hook that lets you defer updating a non-urgent part of the UI, keeping typing or animations responsive.

Q42. What are Custom Hooks?

Reusable JavaScript functions whose names start with 'use' that call other hooks to encapsulate and share stateful logic between components.

Q43. How do you fetch data in React using hooks?

Using useEffect combined with fetch or Axios inside functional components, handling loading and error states via useState.

Q44. Why does state update asynchronously?

Batching updates together across event handlers improves performance by preventing multiple consecutive re-renders.

Q45. How do you update state based on previous state?

By passing a callback function to the state setter (e.g., setCount(prev => prev + 1)) to ensure correct current values.

Q46. What is closure trap in useEffect?

An issue where an effect captures stale state or props values from the render scope where it was defined, requiring correct dependency configuration.

Q47. Can hooks be called conditionally?

No, calling hooks conditionally breaks React's internal linked-list order tracking across renders, causing runtime bugs.

Q48. How do you debug React hook loops?

By verifying that the useEffect dependency array does not contain unstable object/function references that update on every render.

Q49. What is batching in React 18?

Automatic batching groups multiple state updates inside promises, timeouts, and native event handlers into a single re-render cycle.

Q50. What is startTransition API?

An API enabling developers to mark state updates as low-priority transitions so urgent UI updates remain smooth.

Q51. What is code splitting in React?

The technique of splitting code into smaller bundles that are loaded dynamically on demand, improving initial load speeds using dynamic import().

Q52. What is React.lazy()?

A function that lets you render a dynamic import as a regular component, enabling component-level code splitting.

Q53. What is Suspense in React?

A component wrapper that lets your components 'wait' for something before rendering (like lazy-loaded components or asynchronous data fetching), showing a fallback UI.

Q54. What is Server-Side Rendering (SSR)?

Rendering React components on the server into HTML strings sent to the client, improving SEO and initial page load times.

Q55. What is Client-Side Rendering (CSR)?

Rendering pages directly in the browser using JavaScript, where the server sends an empty HTML shell.

Q56. What is Hydration?

The process where React attaches event listeners and brings server-rendered HTML static markup to life on the client side.

Q57. What is React Router?

A standard routing library for React that enables navigation between different views or components in a single-page application (SPA) without page reloads.

Q58. How do you pass parameters in React Router?

Using URL params (e.g., /users/:id accessed via useParams()) or query parameters (accessed via useSearchParams()).

Q59. What is useNavigate hook in React Router?

A hook that returns an imperative navigation function to programmatically navigate between routes.

Q60. What is Context API used for?

Managing global data (themes, auth state, localization) accessible across the component tree without prop drilling.

Q61. What is Redux?

A predictable state container library for JavaScript apps, managing global application state through actions, reducers, and a single store.

Q62. What are actions in Redux?

Plain JavaScript objects that describe an intention to change state, containing a 'type' property and optional payload.

Q63. What are reducers in Redux?

Pure functions that take the previous state and an action, determine how state should transform, and return the new state.

Q64. What is Redux Toolkit (RTK)?

The official, recommended toolset for efficient Redux development, simplifying store setup, reducers, and immutable updates via Immer.

Q65. What is Redux Thunk?

A middleware for Redux that allows action creators to return functions instead of plain objects, enabling asynchronous side effects like API calls.

Q66. What is Zustand?

A small, fast, and scalable state-management library for React using hooks with minimal boilerplate.

Q67. What is Recoil?

A state management library for React providing atomic state sharing with derived data selectors.

Q68. What is React Query (TanStack Query)?

A powerful asynchronous state management library for fetching, caching, synchronizing, and updating server data in React.

Q69. What is Tailwind CSS and how is it used in React?

A utility-first CSS framework that provides low-level atomic classes to build custom designs directly within JSX className attributes.

Q70. What are Error Boundaries in React?

Class components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI.

Q71. Can Functional components act as Error Boundaries?

Not directly via hooks yet; error boundaries currently require lifecycle methods like static getDerivedStateFromError() and componentDidCatch().

Q72. What is memoization in React?

An optimization technique caching calculation results or component renderings to avoid repeated expensive computations.

Q73. How do you optimize React app performance?

Using React.memo, useCallback, useMemo, code splitting, lazy loading, virtualization for long lists, and avoiding inline function definitions where unnecessary.

Q74. What is list virtualization?

Rendering only visible items in a long list instead of all items at once (using libraries like react-window or react-virtualized) to enhance performance.

Q75. What are portals in React?

A mechanism (ReactDOM.createPortal) to render children into a DOM node that exists outside the DOM hierarchy of the parent component (e.g., modals, tooltips).

Q76. How do you test React applications?

Using testing libraries like Jest (test runner) and React Testing Library (RTL) for component assertions and user interactions.

Q77. What is React Testing Library?

A lightweight testing utility focused on testing components from the end-user's perspective by querying DOM elements by accessibility roles and text.

Q78. What is the difference between shallow rendering and deep rendering?

Shallow rendering renders only the target component without its children, whereas deep/full rendering mounts the component along with its entire child subtree.

Q79. What is TypeScript?

A typed superset of JavaScript adding static typing, interfaces, and generics to catch bugs during development.

Q80. How do you define props interfaces in TypeScript with React?

By creating an interface or type alias for component props and annotating the functional component (e.g., const MyComponent: React.FC<Props> = ({...})) .

Q81. What is Vite?

A modern, ultra-fast frontend build tool and development server leveraging native ES modules in the browser and esbuild.

Q82. Why is Vite faster than Create React App (Webpack)?

Vite serves source code over native ESM on-demand without bundling the entire app during dev startup, and uses esbuild written in Go for pre-bundling dependencies.

Q83. What is Next.js?

A popular full-stack React framework providing hybrid static and server rendering, file-based routing, API routes, and built-in optimizations.

Q84. What is the difference between Pages router and App router in Next.js?

Pages router uses file-based routing inside a 'pages' directory with traditional lifecycle conventions, while App router uses React Server Components (RSC) inside an 'app' directory with layouts and streaming support.

Q85. What are React Server Components (RSC)?

Components that execute exclusively on the server, sending zero JavaScript to the client bundle while reducing database query roundtrips.

Q86. What is barrel exporting?

An index.js file pattern aggregating and re-exporting multiple module exports from a folder, simplifying import statements.

Q87. What is prop drilling?

The anti-pattern of passing data through multiple nested intermediate child components just to reach a deeply nested grandchild component.

Q88. How do you prevent prop drilling?

By using React Context API or state management libraries like Redux, Zustand, or Jotai.

Q89. What are render props?

A technique for sharing code between React components using a prop whose value is a function returning JSX.

Q90. What is strict mode concurrency in React?

React 18's concurrent features allow rendering to be paused, resumed, or abandoned, enhancing UI responsiveness.

Q91. What is useId used for in forms?

Generating unique accessibility HTML IDs associating label elements with input fields.

Q92. How do you handle form validation in React?

Using custom validation logic or libraries like Formik and React Hook Form combined with Zod or Yup schemas.

Q93. What is React Hook Form?

A high-performance, flexible form validation library in React that minimizes re-renders using uncontrolled inputs.

Q94. What is Formik?

A popular library helping with form state management, validation, and submission handling in React.

Q95. What is Zod?

A TypeScript-first schema validation library used for runtime data parsing and validation.

Q96. How do you animate components in React?

Using CSS transitions, or animation libraries like Framer Motion, React Spring, or GSAP.

Q97. What is Framer Motion?

An animation and gesture library for React making complex declarative animations extremely easy.

Q98. What are CSS Modules in React?

CSS files where all class names are scoped locally by default, preventing global style collision conflicts.

Q99. What is styled-components?

A CSS-in-JS library that allows writing actual CSS code inside JavaScript components with dynamic props support.

Q100. How do you secure React apps against XSS attacks?

By avoiding raw dangerouslySetInnerHTML unless sanitized (using DOMPurify), and leveraging React's built-in JSX escaping mechanism.

Q101. What happens when you call setState inside render?

It causes an infinite loop because updating state triggers a re-render, which calls render again, throwing a maximum update depth exceeded error.

Q102. What are synthetic events pooling in older React versions?

Event objects were reused across events for performance, meaning properties became nullified asynchronously unless e.persist() was called.

Q103. How do you implement debounce in a React search input?

Using lodash.debounce or a custom setTimeout hook inside useEffect to delay search API requests until the user stops typing.

Q104. How do you implement throttle in React event handlers?

Limiting function execution rate during continuous events like window resizing or scrolling using timer checks.

Q105. What is concurrent rendering in React 18?

An underlying mechanism allowing React to prepare multiple UI versions concurrently without blocking the main browser thread.

Q106. What is useImperativeHandle hook?

A hook that customizes the instance value exposed to parent components when using ref forwarding.

Q107. What is forwardRef?

A technique that passes a ref automatically through a component to one of its children.

Q108. How do you handle authentication in React?

Storing JWT tokens in HttpOnly cookies or localStorage, managing auth state via Context/Redux, and protecting routes using wrapper router guards.

Q109. What is lazy initialization in useState?

Passing a function to useState (e.g., useState(() => expensiveComputation())) so computation runs only once on initial mount.

Q110. Why shouldn't you mutate state directly?

Because mutation bypasses React's diffing detection mechanisms, resulting in stale UI views and unpredictable component states.

Q111. What is Immutability and why is it important in React?

Immutability means data cannot be modified after creation. It allows React to perform fast reference checks (===) to determine if state has changed.

Q112. How do you deep clone state in React?

Using structuredClone(), lodash cloneDeep, or spread operators for shallow cloning.

Q113. What is React Fiber?

React's internal reconciliation engine rewritten from scratch in React 16 to enable incremental rendering and task prioritization.

Q114. What is diffing algorithm in React?

A heuristic O(n) algorithm comparing two virtual DOM trees based on element types and stable keys.

Q115. How do you cancel pending Axios requests on component unmount?

Using an AbortController instance passed into the request config and aborting it inside the useEffect cleanup function.

Q116. What is StrictMode double rendering in development?

React 18 StrictMode intentionally mounts, unmounts, and remounts components in development to help spot unclean side effects and state bugs.

Q117. How do you load external scripts dynamically in React?

Creating a script element inside useEffect, appending it to document.body, and cleaning it up on unmount.

Q118. What is a React wrapper component?

A component designed to enclose other components or layout structures, passing children through props.children.

Q119. What is children prop?

A special prop automatically passed to components containing everything nested between the opening and closing tags of the component JSX.

Q120. How do you handle global errors in React?

Combining Error Boundaries for UI crash recovery and global window error event listeners for unhandled rejections.

Q121. What is Hydration Mismatch error?

An error occurring when server-rendered HTML markup structure doesn't match what the client renders initially.

Q122. How do you solve Hydration Mismatch for client-only components?

By checking typeof window !== 'undefined' or rendering only after component mounts via a hasMounted state flag.

Q123. What is micro-frontend architecture in React?

Splitting a monolithic frontend app into smaller, independent, loosely coupled React applications integrated together.

Q124. What is module federation in Webpack?

A feature allowing a React application to dynamically load code and components from another separate build runtime at runtime.

Q125. How do you optimize image loading in React?

Using modern formats (WebP/AVIF), responsive srcset sizes, native lazy loading (loading='lazy'), or Next.js Image component.

Q126. What is tree shaking?

A dead-code elimination technique used by bundlers (Webpack/Vite) to remove unused imported modules from production builds.

Q127. What are React Server Actions?

Asynchronous functions executed on the server, callable directly from client components (popularized in Next.js).

Q128. What is optimistic UI updates?

Updating the UI immediately on user action assuming the server request will succeed, and rolling back if it fails.

Q129. What is state normalization?

Structuring relational state in Redux or stores like a database table (keyed by IDs) to avoid nested data update duplication.

Q130. What is infinite scrolling in React?

Loading more items automatically as the user scrolls down using Intersection Observer API.

Q131. What is Intersection Observer API in React?

A browser API used to observe visibility changes of DOM elements, ideal for lazy loading images or infinite scroll.

Q132. How do you unit test custom hooks?

Using @testing-library/react renderHook utility to test hook state and behavior in isolation.

Q133. What is mock service worker (MSW)?

An API mocking library that intercepts network requests at the network level for robust testing and development.

Q134. What is Cypress / Playwright in React testing?

End-to-end (E2E) testing frameworks simulating real user browser workflows.

Q135. What is Storybook?

A development environment and playground for isolated UI component building and testing.

Q136. What is headless UI?

Unstyled, accessible UI component primitives (like Radix UI or Headless UI) providing complete styling freedom.

Q137. What is Radix UI?

A collection of low-level, accessible UI primitives for building high-quality design systems in React.

Q138. What is Shadcn UI?

A popular collection of re-usable components built using Radix UI and Tailwind CSS that you copy-paste into your codebase.

Q139. How do you manage internationalization (i18n) in React?

Using libraries like react-i18next or formatjs to support multi-language text translation.

Q140. What is accessibility (a11y) in React?

Ensuring web apps are usable by people with disabilities using ARIA attributes, semantic HTML tags, and keyboard navigation.

Q141. What are ARIA attributes?

Accessible Rich Internet Applications attributes (like aria-label, aria-expanded) aiding screen readers.

Q142. How do you manage focus traps in React modals?

Ensuring keyboard focus stays inside active modal dialogs using libraries or custom tab key listeners.

Q143. What is memory leak in React?

Uncleaned timers, subscriptions, or async state updates performed on unmounted components.

Q144. How do you fix 'Can't perform a React state update on an unmounted component' warning?

By cancelling subscriptions or setting an isMounted cancellation flag in useEffect cleanup.

Q145. What is React DevTools?

A browser extension for inspecting React component hierarchies, props, state, and profiling performance.

Q146. How do you profile component render times?

Using the React DevTools Profiler tab to measure exact render costs and identify bottlenecks.

Q147. What is state lifting (Lifting State Up)?

Moving state from child components to their closest common parent component so multiple children can share it.

Q148. What is component composition?

Building complex components out of smaller ones using props.children rather than inheritance.

Q149. Why React prefers composition over inheritance?

Because component composition provides cleaner, more flexible code reuse without deep class hierarchies.

Q150. What is a container and presentational component pattern?

Separating components into 'smart' container components handling data/logic and 'dumb' presentational components focusing purely on UI rendering.

Q151. What are compound components pattern?

A pattern where components work together (like <Select><Option/></Select>) sharing implicit state via context.

Q152. What is custom hook pattern for data abstraction?

Encapsulating API calls and state management inside dedicated hooks to keep UI components clean.

Q153. What is control props pattern?

Allowing a component's state to be controlled externally by props while supporting uncontrolled internal fallbacks.

Q154. What is state reducer pattern?

Giving users control over internal component state transitions by accepting a custom reducer function as a prop.

Q155. What is polymorphic 'as' prop pattern?

Allowing a React component to render as any HTML tag or React component dynamically via an as prop.

Q156. How do you handle pagination in React tables?

Splitting data arrays into fixed-size pages using slice() and managing active page state.

Q157. How do you implement client-side table sorting?

Using JavaScript sort() array method on data state based on selected column key and order direction.

Q158. How do you implement table search filtering?

Using filter() array method checking if row values include search query strings.

Q159. How do you export table data to CSV in React?

Converting JSON data arrays into CSV string blobs and triggering a file download via Blob and createObjectURL.

Q160. How do you generate PDFs in React?

Using libraries like @react-pdf/renderer or jspdf to create downloadable PDF documents.

Q161. How do you handle clipboard copy in React?

Using navigator.clipboard.writeText() inside click handlers.

Q162. How do you detect screen size changes in React?

Using window.matchMedia or custom hooks listening to window resize event listeners.

Q163. How do you implement dark mode in React?

Toggling a CSS class on the root document element and persisting preference in localStorage or Tailwind dark class.

Q164. How do you handle offline detection in React?

Using navigator.onLine and listening to online/offline window events.

Q165. What is service worker in React PWAs?

A script running in the background enabling Progressive Web App offline caching and push notifications.

Q166. What is Web Workers in React?

Running heavy computations in background worker threads so the main UI thread remains completely unblocked.

Q167. How do you pass data between sibling components?

By lifting the state up to their nearest common parent component.

Q168. What is strict equality check in React.memo?

React.memo performs a shallow comparison of props by default; custom comparison functions can override this behavior.

Q169. Why does React re-render parent when child state changes?

Parent re-renders only if its own state or props change, but a parent re-render naturally causes all its children to re-render unless memoized.

Q170. How do you prevent unnecessary re-renders of child components?

Wrapping the child component with React.memo and passing memoized callbacks/objects.

Q171. What is stale closure problem in React hooks?

When an asynchronous callback or effect references old state values captured during its initial render scope.

Q172. How do you solve stale closures with useRef?

Storing mutable reference values in useRef that always point to the latest current values without triggering re-renders.

Q173. What is atomic design methodology in React?

Structuring components into atoms, molecules, organisms, templates, and pages.

Q174. How do you handle environment variables in React (Vite)?

Using import.meta.env.VITE_VARIABLE_NAME with variables prefixed with VITE_.

Q175. How do you handle environment variables in React (CRA)?

Using process.env.REACT_APP_VARIABLE_NAME.

Q176. What is dynamic imports in code splitting?

Importing modules asynchronously only when needed using import('./module').

Q177. What is prefetching in React Router / Next.js?

Loading route code and data in the background before the user actually clicks the navigation link.

Q178. What is React Suspense list?

An experimental or advanced component coordinating multiple suspense loading boundaries.

Q179. How do you handle nested routing in React Router?

Using parent routes with <Outlet /> placeholders to render child route components.

Q180. What are protected routes in React?

Wrapper components checking if a user is authenticated before rendering target private pages or redirecting to login.

Q181. What is lazy loading images with IntersectionObserver?

Loading image src attributes only when they scroll into the browser viewport.

Q182. How do you implement drag and drop in React?

Using HTML5 drag and drop events or libraries like @hello-pangea/dnd or dnd-kit.

Q183. What is dnd-kit?

A modern, lightweight, accessible drag and drop toolkit for React.

Q184. How do you create charts in React?

Using charting libraries like Chart.js (react-chartjs-2), Recharts, or Victory.

Q185. What is Recharts?

A composable charting library built on React components and D3.

Q186. How do you handle rich text editing in React?

Using editors like TinyMCE, Quill (react-quill), or Lexical by Meta.

Q187. What is Lexical?

An extensible JavaScript web text-editor framework built by Meta with React support.

Q188. How do you manage modals globally in React?

Using a global modal context store to open/close modal components from anywhere in the app.

Q189. How do you handle toast notifications in React?

Using notification libraries like react-hot-toast or react-toastify.

Q190. What is memoization overhead?

Overusing useMemo or useCallback on cheap calculations where the comparison cost outweighs re-render savings.

Q191. How do you handle API request cancellation?

Using AbortController signal passed into fetch or axios instance.

Q192. What is state persistence?

Saving application state to localStorage or sessionStorage so it survives page reloads.

Q193. How do you implement undo/redo functionality in React state?

Maintaining past, present, and future state history arrays inside useReducer or custom hooks.

Q194. What is optimistic locking vs optimistic UI?

Optimistic locking is a database concurrency control, while optimistic UI is updating frontend views instantly before server confirmation.

Q195. How do you write clean React folder structures?

Organizing by feature modules (/features/auth, /features/dashboard) or by file type (/components, /hooks, /services).

Q196. What are React design patterns for scalability?

Container/Presentational, Custom Hooks abstraction, Compound Components, and Atomic Design.

Q197. How do you secure forms against CSRF in React apps?

Ensuring cookies have SameSite=Strict and validating CSRF tokens provided by backend APIs.

Q198. What is tree-shaking friendly package design?

Writing modular ES exports so bundlers can easily eliminate unused code during compilation.

Q199. Why is key prop crucial in dynamic lists?

It enables React's reconciliation algorithm to track node identity precisely, avoiding UI mismatch bugs and expensive unmount/remount cycles.

Q200. What is the future direction of React?

Moving heavily toward React Server Components (RSC), server actions, streaming SSR, automatic suspense, and zero-bundle-size optimizations.