React Interview Questions and Answers

These are the React questions you'll encounter in technical interviews, each with a detailed written answer. Master components and hooks, then work through state management, performance, and advanced patterns.

40 questions with answersLast updated: Oct 10, 2026
Start a mock interview

What is React?

React is a JavaScript library for building user interfaces with reusable, component-based architecture. Developed by Meta, it's the most popular frontend framework and powers millions of web applications.

React interviews focus on components, hooks, state management, rendering, and performance optimization. You'll discuss the virtual DOM, lifecycle methods, and how to build scalable, maintainable UIs.

React expertise is essential for modern frontend development. Master the library and you'll be competitive for frontend and full-stack roles at top companies.

Reading answers is not the same as giving them. Sit a full mock interview and get scored on how you actually explain them.

Try a mock interview

React Interview Questions and Answers

1Multiple choice

How would you describe React and what problems does it solve in UI development?

Answer

React solves: managing complex UI state, reusing components across applications, efficient DOM updates through Virtual DOM diffing. It enables building scalable, maintainable applications.

2Multiple choice

Explain JSX syntax and how it enables writing markup-like code in JavaScript

Answer

JSX looks like HTML but is JavaScript. Babel transforms JSX to React.createElement. Enables readable UI code. JavaScript expressions wrapped in braces.

3Multiple choice

What are React components and how do functional and class components differ?

Answer

Functional components are functions returning JSX. Class components extend React.Component. Modern React prefers functional components with hooks. Both are equivalent in capability.

4Multiple choice

How does the Virtual DOM improve performance compared to direct DOM manipulation?

Answer

React compares old and new Virtual DOM tree. Identifies minimal changes needed. Batches updates for efficiency. Reduces reflows and repaints. Dramatically faster than updating entire DOM.

5Multiple choice

Contrast props and state, explaining when to use each and data flow

Answer

Props are read-only data passed from parent to child. State is mutable data managed by component. State changes via setState trigger re-renders. Props changes also trigger child re-renders.

6Multiple choice

Explain useState hook and how it enables state management in functional components

Answer

const state, setState = useState initialValue. Setter setState updates state and triggers re-render. Multiple useState calls allowed. Hooks enable replacing class state with cleaner functional syntax.

7Multiple choice

Describe useEffect and how to handle side effects with dependency arrays

Answer

useEffect runs after component renders. Dependency array controls execution: empty runs once, omitted runs every render, with dependencies runs when dependencies change. Cleanup function handles unmounting.

8Multiple choice

Explain state lifting and when to move state up the component tree

Answer

When multiple child components need same state, move it to closest common parent. Parent becomes source of truth. Children receive state and setState via props. Enables synchronization.

9Multiple choice

How does Context API solve prop drilling and enable global state management?

Answer

Create Context with createContext. Wrap tree with Provider. useContext hook accesses value. Eliminates passing props through intermediate components. Perfect for themes, auth, language.

10Multiple choice

Explain hooks and how they enable using state in functional components

Answer

Hooks enable functional components to use state, effects, context, and other features. Follow rules: call only at top level, never conditionally. Enables cleaner code than class components.

11Written answer

Describe React's purpose, component-based architecture, and ecosystem

Answer

React is a JavaScript library for building user interfaces with components. Component-based architecture breaks UI into reusable pieces. Each component manages its own state and props. Components compose together to build applications. React ecosystem includes: React Router for navigation, Redux or Context for state management, testing libraries like Jest and React Testing Library, build tools like Webpack or Vite. React is maintained by Meta and community. Huge ecosystem enables building complex applications.

12Written answer

Explain how JSX is transformed to JavaScript and React.createElement calls

Answer

JSX is syntactic sugar. Babel transpiler converts JSX to React.createElement calls. Example: div className hello transforms to React.createElement div classNamehello null children. JavaScript expressions in braces are evaluated. Attributes become props. Children become additional arguments. Understanding transformation helps debug and use JSX effectively. JSX is not valid JavaScript alone; requires build step.

13Written answer

Explain functional components, class components, and why functional components are preferred

Answer

Functional components are JavaScript functions returning JSX. Simple, testable, lightweight. Class components extend React.Component, use this.state and lifecycle methods. More verbose. Modern React prefers functional components with hooks because they are cleaner, smaller bundle size, easier to compose and test. Hooks provide equivalent capabilities to class features. New projects should use functional components. Class components still work but are legacy.

14Written answer

Describe diffing algorithm, reconciliation, and why Virtual DOM improves performance

Answer

React maintains Virtual DOM in memory. After state change, creates new Virtual DOM tree. Diffing algorithm compares old and new trees, identifies changes. Reconciliation applies minimal DOM updates. Batches multiple updates together. This avoids expensive reflows and repaints. Direct DOM manipulation requires updating entire sections; React updates only changed elements. Dramatically improves performance on complex applications.

15Written answer

Explain unidirectional data flow, prop drilling, and composition over inheritance

Answer

Unidirectional flow: data flows down from parent to child via props. Children cannot directly modify parent state; they call parent callback functions. This predictability aids debugging. Prop drilling: passing props through multiple intermediate components. Solved with Context API or composition. Composition over inheritance: build components by combining smaller components rather than extending base classes. More flexible, reusable, maintainable.

16Written answer

Describe state updates, closure behavior, and common useState patterns

Answer

useState returns array: state value and setState function. setState updates state and queues re-render. setState can take value or function for previous state. State updates are asynchronous. Multiple setState calls batch together. Closures capture current state; stale state can occur without proper dependencies. Common patterns: toggles with boolean, form state with object, arrays with spread operator or hooks like useReducer for complex state.

17Written answer

Explain side effects, cleanup functions, and dependency array optimization

Answer

Side effects are operations outside pure rendering: API calls, subscriptions, timers, DOM manipulation. useEffect runs after render. Return function from useEffect is cleanup, runs before re-render and on unmount. Dependency array optimizes: omitted means run every render, empty means run once on mount, with dependencies means run when dependencies change. Proper dependencies prevent bugs and unnecessary runs.

18Written answer

Explain component communication, shared state patterns, and alternatives

Answer

Child to parent: callback functions passed via props. Parent calls setState in callback. Multiple children: lift state to common parent, pass state and setState via props. Siblings communicate through parent. Complex apps use Context API or state management like Redux. Composition enables encapsulating related components. Custom hooks enable sharing logic between components without component nesting.

19Written answer

Explain Context, Provider, and Consumer; compare to Redux

Answer

Context: createContext creates context object. Provider wraps component tree, provides value. useContext hook accesses value in consumers. Simple for small to medium apps. Redux: centralized store, actions, reducers. More complex setup. Better for large apps with complex state logic and middleware needs. Redux enables time-travel debugging. Context is built-in, Redux is external library.

20Written answer

Explain useState, useEffect, useContext, useReducer, useMemo, useCallback and custom hooks

Answer

useState manages local state. useEffect handles side effects. useContext accesses context value. useReducer manages complex state with actions, alternative to multiple useState calls. useMemo memoizes computed values, prevents recalculation on every render. useCallback memoizes functions, prevents unnecessary re-renders of child components receiving function as prop. Custom hooks: functions starting with use, combine built-in hooks to create reusable logic.

21Spoken answer

Walk through how you would build a counter component with state management

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

I created a counter component with useState. Initial state 0. Button onClick handler calls setCount with count plus 1. Each update triggers re-render, displaying new count. Used useCallback to memoize handler to prevent unnecessary re-renders if component received other prop changes.

22Spoken answer

Describe a situation where you had to lift state and how it improved component communication

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

Parent component had toggle state. Two sibling child components needed to coordinate: only one could be expanded. I lifted toggle state to parent. Parent passed state and setState via props to children. Children now communicate through parent callbacks. This made components independent and reusable.

23Spoken answer

Explain how you would fetch data in a component using useEffect

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

I used useEffect with empty dependency array to fetch on mount. API call inside effect returns data. useState stored fetched data. useEffect cleanup function cancelled requests on unmount preventing memory leaks. Added error handling and loading state. Dependency array with id parameter fetched when id changed.

24Spoken answer

Talk about debugging a performance issue caused by unnecessary re-renders

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

React DevTools Profiler showed components re-rendering unnecessarily. I added React.memo to prevent re-renders when props didn't change. useCallback memoized functions passed as props. useMemo memoized computed values. Identified that Parent re-renders triggered all children re-renders. Optimizations reduced re-renders significantly.

25Spoken answer

Describe implementing a form with controlled components

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

I used controlled components: input value from state, onChange handler updates state. Select with value and onChange. Checkbox with checked and onChange. Form submit handler validates and submits. All form state managed in React, making validation and submission predictable.

26Spoken answer

Explain how you would use Context API to manage theme switching

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

I created ThemeContext with createContext. ThemeProvider component managed theme state. useContext theme hook in consumers accessed current theme. Toggle button changed theme. CSS applied different styles based on theme. Context avoided prop drilling through many components.

27Spoken answer

Walk through creating a custom hook for reusable logic

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

I created useLocalStorage custom hook: useState persists to localStorage, useEffect syncs changes, returns state and setter. useForm hook: manages form state with validation, returns values, errors, handleChange, handleSubmit. Custom hooks enabled reusing logic across multiple components without code duplication.

28Spoken answer

Talk about handling error boundaries in React applications

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

Error boundaries catch errors in child component tree. I created ErrorBoundary class component with componentDidCatch lifecycle. Displayed error UI instead of crashing app. Wrapped risky components in boundary. Error boundaries don't catch event handler errors or async errors; try-catch handles those.

29Spoken answer

Describe how you would test a React component

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

I used React Testing Library to test components. render renders component. screen queries found elements. userEvent simulates user interactions like clicks and typing. expect assertions verify behavior. Testing component with mock functions verified correct callbacks were called. Testing focused on user behavior not implementation details.

30Spoken answer

Explain how you would optimize a large list rendering

This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.

Answer

Virtual list rendering: only render visible items. react-window library virtualized list. Memoized row components with React.memo. Sorted large lists with efficient algorithms. useTransition deferred updates. Pagination instead of infinite scroll. Resulted in 60fps performance even with thousands of items.

31Coding

Create a counter component that increments and decrements using useState

Build your React component here

Answer

function Counter() { const count, setCount useState 0; return div button onClick={() setCount(count + 1)} Increment /button button onClick={() setCount(count - 1)} Decrement /button p Count: {count} /p /div }
32Coding

Build a controlled form component with input validation

Build your React component here

Answer

function Form() { const email, setEmail useState ''; const handleSubmit (e) => { e.preventDefault; if valid email setEmail ''; } return form onSubmit={handleSubmit} input value={email} onChange={(e) setEmail(e.target.value)} /form }
33Coding

Fetch data from an API using useEffect with loading and error states

Build your React component here

Answer

function DataFetch() { const data, setData useState null; const loading, setLoading useState true; useEffect(() => { fetch url .then(res => res.json()) .then(data => setData data) .catch(err => setError err) .finally(() => setLoading false); }, []); return loading p Loading /p : error p Error /p : data div ... /div }
34Coding

Render a list of items with proper keys and click handlers

Build your React component here

Answer

function List() { const items = itemsArray; return ul {items.map(item => li key={item.id} onClick={() handleClick item.id {item.name} /li)} /ul }
35Coding

Use conditional rendering to show different UI based on state

Build your React component here

Answer

function Status() { const isLoggedIn, setIsLoggedIn useState false; return isLoggedIn ? p Welcome back /p : p Please log in /p }
36Coding

Create a custom hook that manages form input state

Build your React component here

Answer

function useFormInput initialValue { const value, setValue useState initialValue; return { value, onChange: (e) => setValue e.target.value } }
37Coding

Implement Context API for managing global theme state

Build your React component here

Answer

const ThemeContext createContext; function ThemeProvider { children } { const theme, setTheme useState light; return ThemeContext.Provider value={{theme, setTheme}} {children} /ThemeContext.Provider }
38Coding

Use useCallback to prevent unnecessary re-renders of child components

Build your React component here

Answer

function Parent() { const handleChange useCallback ((data) => console.log data, []); return Child onChange={handleChange} /Child }
39Coding

Use useMemo to memoize expensive computations

Build your React component here

Answer

function Expensive() { const result useMemo (() => expensiveCalculation someValue, [someValue]); return div {result} /div }
40Coding

Build reusable components by composing smaller components

Build your React component here

Answer

function Card() { return div Card content /div } function CardList() { return div Card /Card Card /Card /div }