React Interview Question Bank: Junior to Senior Level
A comprehensive collection of React interview questions organized by experience level and difficulty. These questions cover fundamentals, hooks, components, state management, performance optimization, architecture patterns, and more.
Junior Level Questions
Fundamentals (Easy)
- What is React and what are its main features?
- Explain the difference between a library and a framework. Where does React fit in?
- What is JSX and how does it work?
- What is the Virtual DOM and why is it important?
- How does React differ from vanilla JavaScript?
- What are props in React?
- What is state in React?
- Explain the difference between props and state.
- What is the significance of keys in React lists?
- What is the default direction of data flow in React?
Components (Easy)
- What are React components?
- What's the difference between functional and class components?
- What are pure components?
- What is the difference between a controlled and an uncontrolled component?
- When would you use a class component over a functional component?
- What is prop drilling and why can it be problematic?
- What is a higher-order component (HOC)?
- What are React fragments and why are they useful?
- How do you create a ref in React?
- What is the purpose of the
key
prop when rendering a list of components?
Hooks (Easy)
- What are React hooks and why were they introduced?
- Explain the useState hook with an example.
- What does the useEffect hook do?
- How do you skip effects on certain renders using useEffect?
- What are the rules of hooks?
- What is the useContext hook used for?
- How do you create a custom hook?
- What is the useRef hook and what's a common use case?
- How is useState different from this.setState in class components?
- What problems do hooks solve that couldn't be solved with class components?
Practical Implementation (Easy-Medium)
- Implement a simple counter component using useState.
- Create a toggle button that changes its text between "ON" and "OFF".
- How would you fetch data from an API in a functional component?
- Implement a basic form with form validation using React hooks.
- Create a component that displays a list of items from props.
- How would you conditionally render content in React?
- Implement dark mode toggling in a simple app using React.
- Create a component that displays the window size and updates when resized.
- Implement a simple todo list that allows adding and removing items.
- Create a component that filters a list based on a search input.
Mid-Level Questions
Advanced Hooks (Medium)
- Explain the useReducer hook and when you would use it over useState.
- What is useCallback and why is it useful?
- How does useMemo work and when should you use it?
- What's the difference between useCallback and useMemo?
- How would you implement a custom hook for form handling?
- What is useLayoutEffect and how does it differ from useEffect?
- Explain how to use useContext with useReducer to manage global state.
- How would you implement a debounce function using hooks?
- What are the performance implications of using many context providers?
- How would you implement a custom useLocalStorage hook?
Performance (Medium)
- What is React.memo and when should you use it?
- Explain how to optimize re-renders in functional components.
- What causes unnecessary re-renders in React and how can you prevent them?
- What is code splitting in React and how does it improve performance?
- How would you optimize a React application that renders large lists?
- What is lazy loading in React and how does it work?
- How do you profile and measure performance in a React application?
- What are common performance pitfalls in React applications?
- Explain the concept of "lift state up" and its performance implications.
- How do you prevent memory leaks in React components?
State Management (Medium)
- Compare React Context API and Redux for state management.
- When would you use Context API versus a state management library?
- Explain the concept of actions, reducers, and the store in Redux.
- What is Redux Toolkit and how does it simplify Redux usage?
- What are side effects in Redux and how are they typically handled?
- When would you use Zustand over Redux?
- How would you structure a global state for a medium-sized application?
- What are the common pitfalls when using Context API for state management?
- How would you handle asynchronous operations in Redux?
- Compare different state management approaches: Redux, Context API, MobX, and Zustand.
Testing (Medium)
- What is Jest and React Testing Library? How do they work together?
- How do you test a React component with hooks?
- What is the difference between shallow rendering and full rendering in tests?
- How do you mock API calls in React component tests?
- How do you test components that use Context API?
- What is snapshot testing and when should you use it?
- How do you test user interactions like clicking or form submissions?
- Explain how to test asynchronous operations in React components.
- What are common testing patterns for React applications?
- How do you set up test coverage for a React application?
Practical Implementation (Medium)
- Implement a custom hook that handles API calls with loading, error, and data states.
- Create a form with multiple steps (wizard) in React.
- Implement a datepicker component from scratch.
- Create a responsive image gallery with modal previews.
- Implement a dropdown menu with keyboard navigation.
- Create a custom hook for handling infinite scrolling.
- Implement a form with dynamic fields that can be added or removed.
- Create a custom drag and drop interface without external libraries.
- Implement a component that efficiently renders a large table with sorting and filtering.
- Build a custom autocomplete component that fetches suggestions from an API.
Senior Level Questions
Architecture (Hard)
- How would you architect a large-scale React application with multiple teams?
- What are micro-frontends and how might you implement them with React?
- How do you manage code sharing between React applications?
- Explain how you would implement a design system in a React application.
- What strategies would you use to optimize the build size of a React application?
- How would you handle authentication and authorization in a React application?
- Describe your approach to error handling in a complex React application.
- How would you implement internationalization in a React application?
- What are your strategies for maintaining code quality in a large React codebase?
- How would you architect a mono-repo containing multiple React applications?
Advanced Patterns (Hard)
- Explain the compound component pattern with an example.
- What is the render props pattern and when would you use it?
- Explain the state reducer pattern in React.
- How does the provider pattern work and when should it be used?
- What is the container/presentational pattern and why is it useful?
- Explain the custom hook composition pattern.
- What is the controlled props pattern?
- Explain how the observer pattern can be implemented in React.
- What is the component composition pattern?
- How and when would you implement the context module functions pattern?
Performance Optimization (Hard)
- How would you identify and resolve rendering performance issues in a React application?
- Explain strategies for optimizing initial load time in a React application.
- How would you implement effective code splitting in a complex React application?
- What techniques would you use to optimize React Context performance?
- How would you handle virtualization for very large lists in React?
- Explain how you would optimize images and assets in a React application.
- What strategies would you implement for efficient data fetching in React?
- How would you optimize Redux store for a large-scale application?
- Explain techniques for reducing JS bundle size in a React application.
- How would you implement efficient real-time updates in a React application?
State Management (Hard)
- Design a state management solution for a complex form with interdependent fields.
- How would you implement optimistic updates with error handling in a React application?
- Design a state management architecture for an application with real-time collaborative features.
- How would you handle caching and state normalization in a complex React application?
- What approaches would you take to handle derived state efficiently?
- Explain how you would implement an undo/redo feature in a React application.
- How would you structure application state for offline-first capabilities?
- Design a state management approach for a multi-tenant application.
- How would you implement state persistence across sessions with proper security?
- Design a state management architecture that synchronizes with a backend service.
System Design (Hard)
- Design a real-time dashboard that displays data from multiple sources.
- How would you design a collaborative document editing system in React?
- Design a large-scale e-commerce product catalog with filtering and search capabilities.
- How would you architect a social media feed with infinite scrolling and real-time updates?
- Design a file upload system with progress tracking and resumable uploads.
- How would you implement a complex multi-step checkout process?
- Design a video streaming application with React.
- How would you build a design tool similar to Figma or Canva using React?
- Design a system for a multi-user calendar application.
- How would you architect a code-sharing application like CodePen?
Team Leadership (Hard)
- How do you handle technical debt in a React codebase?
- What strategies would you use to onboard new developers to a complex React codebase?
- How would you guide junior developers in writing maintainable React components?
- What's your approach to implementing new React features or patterns in an existing codebase?
- How would you make technical decisions on adopting new React libraries or patterns?
- What's your strategy for keeping a team updated with the latest React best practices?
- How would you structure code reviews for React components?
- What metrics would you track to measure the quality of a React codebase?
- How would you handle disagreements within a team about React architecture decisions?
- What's your approach to balancing feature development with maintaining React code quality?
Answer Hints
Junior Level Hints
-
React is a JavaScript library for building user interfaces, with features like Virtual DOM, component-based architecture, and unidirectional data flow.
-
Libraries provide specific functionality to be called by your code, while frameworks call your code. React is a library.
-
JSX is a syntax extension for JavaScript that looks like HTML. It's transformed to React.createElement() calls.
-
Virtual DOM is a lightweight copy of the actual DOM that React uses to optimize rendering performance through diffing.
-
React uses a component-based approach and Virtual DOM, while vanilla JS directly manipulates the DOM.
-
Props are read-only data passed from parent to child components.
-
State is internal data managed by a component that can change over time.
-
Props are passed from parent components and are read-only, while state is managed within the component and mutable.
-
Keys help React identify which items have changed, been added, or removed, improving reconciliation performance.
-
Data flows down from parent to child components (unidirectional).
-
Components are reusable, self-contained pieces of UI.
-
Functional components are JavaScript functions that accept props and return elements. Class components extend React.Component and have more built-in features.
-
Pure components implement shouldComponentUpdate with a shallow prop and state comparison to prevent unnecessary renders.
-
Controlled components are managed by React state, while uncontrolled components maintain their own state in the DOM.
-
Class components were needed for state and lifecycle methods before hooks, or when using error boundaries.
-
Prop drilling is passing props through many components that don't need them, making code harder to maintain.
-
HOCs are functions that take a component and return a new enhanced component.
-
Fragments let you group elements without adding extra nodes to the DOM.
-
Create refs using createRef() (class) or useRef() (functional).
-
Keys identify elements in lists, helping React optimize rendering.
-
Hooks let functional components use state and lifecycle features, promoting code reuse.
-
useState returns current state and a setter function, e.g., const [count, setCount] = useState(0).
-
useEffect runs side effects after renders, handling lifecycle events like componentDidMount/Update/Unmount.
-
Use dependency arrays in useEffect - empty array ([]) for once after mount, specified dependencies for conditional runs.
-
Only call hooks at the top level and in React functions, not in conditions or loops.
-
useContext consumes values from React Context without nested render props or HOCs.
-
Custom hooks are functions starting with "use" that can call other hooks.
-
useRef persists values between renders without causing re-renders; common for DOM element references.
-
useState returns a current value and setter, while this.setState merges state updates and handles asynchronous updates.
-
Hooks allow reusing stateful logic between components, avoid class confusion, and group related code.
31-40. These questions require implementing specific React components, focusing on basic state management, event handling, conditional rendering, and common UI patterns.
Mid-Level Hints
-
useReducer handles complex state logic through actions and reducers, similar to Redux.
-
useCallback memoizes functions to prevent unnecessary recreation between renders.
-
useMemo memoizes computed values to prevent recalculation on every render.
-
useCallback returns a memoized function, while useMemo returns a memoized value.
-
Custom form hooks typically manage form state, validation, and submission handling.
-
useLayoutEffect runs synchronously after DOM mutations but before browser painting, while useEffect runs asynchronously after painting.
-
Combine useContext and useReducer by creating a context with a reducer, providing dispatch and state.
-
Implement debounce with useCallback, useState, and useEffect to manage timers.
-
Multiple context providers can cause performance issues due to separate re-render cascades.
-
useLocalStorage hook would use useState with localStorage for persistence.
-
React.memo prevents re-renders when props haven't changed, useful for optimizing pure functional components.
-
Optimize with memoization (React.memo, useMemo, useCallback) and proper component structure.
-
Unnecessary re-renders happen when parents re-render, state changes, or reference equality breaks for objects/functions.
-
Code splitting breaks code into smaller chunks loaded on demand, improving initial load time.
-
Virtualize large lists to render only visible items using libraries like react-window.
-
Lazy loading defers loading components until needed using React.lazy and Suspense.
-
Use React DevTools Profiler, Lighthouse, or custom measurements for performance profiling.
-
Common pitfalls include unnecessary re-renders, inefficient state updates, and large component trees.
-
"Lifting state up" moves state to common ancestors, potentially causing cascading re-renders.
-
Clean up subscriptions, timers, and event listeners in useEffect return functions.
-
Context API is built into React but simple; Redux provides a more structured approach with middleware support.
-
Use Context for low-frequency updates and theme/auth data; use Redux for complex state with many updates.
-
Actions describe state changes, reducers implement them, and the store holds the global state.
-
Redux Toolkit reduces boilerplate with createSlice, includes Redux Thunk, and uses Immer for immutability.
-
Side effects (API calls, etc.) are typically handled with middleware like thunk or saga.
-
Zustand is simpler, has less boilerplate, and better performance for many scenarios.
-
Organize by domain, normalize data, separate UI from domain state, and keep state minimal.
-
Context causes re-renders of all consumers when value changes and lacks middleware support.
-
Use middleware like thunk or saga to handle async operations in Redux.
-
Compare based on boilerplate, performance, debugging, team familiarity, and application needs.
-
Jest is a test runner; React Testing Library focuses on testing from a user perspective.
-
Test hooks through the components that use them or with the React Hooks Testing Library.
-
Shallow renders just the component; full rendering includes child components.
-
Mock API calls using jest.mock() or a library like MSW (Mock Service Worker).
-
Wrap components with the appropriate Context Provider in tests.
-
Snapshot testing captures component output for regression testing but can be brittle.
-
Use fireEvent or userEvent from Testing Library to simulate interactions.
-
Use async/await with waitFor or findBy queries to test asynchronous operations.
-
Common patterns include AAA (Arrange-Act-Assert), component testing, and integration testing.
-
Configure Jest with coverage reporters and threshold requirements.
81-90. These questions require implementing more complex React components and custom hooks, focusing on real-world scenarios.
Senior Level Hints
-
Focus on modular architecture, shared libraries, clear boundaries, state management strategy, and documentation.
-
Micro-frontends split applications into smaller, independently deployable frontend apps, using approaches like iframes, web components, or module federation.
-
Options include shared npm packages, mono-repos, and module federation.
-
Implement a design system with component libraries, styling systems, documentation, and versioning strategies.
-
Apply code splitting, tree shaking, dynamic imports, and proper dependency management.
-
Consider JWT, OAuth, role-based access control, and secure state management.
-
Use error boundaries, global error handlers, consistent error states, and monitoring.
-
Use libraries like i18next, manage translations, handle locale-specific formatting, and consider RTL support.
-
Implement linting, testing, code reviews, documentation, and architecture decisions records.
-
Use tools like Nx, Lerna, or Turborepo with shared configurations, libraries, and CI/CD pipelines.
-
Compound components share state implicitly through context, like select/option or tabs/tab-panel.
-
Render props pass rendering logic via a function prop, enabling component composition.
-
State reducer pattern allows consumers to control state updates by providing a custom reducer.
-
Provider pattern uses context to provide state/functions to deeply nested components.
-
Container components handle data/logic; presentational components handle rendering/UI.
-
Custom hook composition combines multiple hooks into more complex ones.
-
Controlled props enable parent components to control child component state.
-
Observer pattern uses subscriptions to notify components of state changes.
-
Component composition builds complex UIs from simpler components, favoring composition over inheritance.
-
Context module functions expose functions that operate on context state, keeping logic in one place.
-
Identify with React DevTools Profiler, fix with memoization, code splitting, and better component structure.
-
Optimize with server-side rendering, code splitting, lazy loading, and proper bundling.
-
Implement route-based, component-based, and feature-based code splitting.
-
Split contexts by update frequency, memoize provider values, and keep context consumers small.
-
Use virtualization libraries with proper configuration for variable heights and cacheing.
-
Optimize with lazy loading, proper sizing, next-gen formats, and image CDNs.
-
Implement data fetching libraries, request deduplication, caching, and optimistic updates.
-
Use normalization, selectors, batched actions, and consider Redux Toolkit.
-
Apply tree shaking, dynamic imports, dependency optimization, and proper bundling.
-
Implement WebSockets or long polling with proper state updates and error handling.
-
Combine useReducer with field-level validation, dependent field logic, and optimized re-renders.
-
Update UI optimistically, store previous state, revert on error, and retry mechanisms.
-
Implement real-time sync with WebSockets, conflict resolution, and offline capabilities.
-
Use normalized state with libraries like normalizr, implement proper cache invalidation, and use selectors.
-
Use memoization, compute derived state on-demand, and consider libraries like Reselect.
-
Implement command pattern with action history and state snapshots.
-
Use IndexedDB or localStorage with sync mechanisms and conflict resolution.
-
Implement tenant isolation, shared vs. tenant-specific state, and proper security.
-
Use secure storage (HttpOnly cookies, encryption), sanitize on load, and handle migrations.
-
Design bidirectional sync with optimistic updates, conflict resolution, and offline support.
131-140. These questions test your ability to design complex React applications for specific domains.
141-150. These questions assess leadership and technical decision-making in React projects.