Top 100 Interview Questions and Answers on React JS & Redux

  • By Sonal Vanarse
  • February 12, 2025
  • JavaScript
Top 100 Interview Questions and Answers on React JS & Redux

Top 100 Interview Questions and Answers on React JS & Redux

Prepare for your interview with these Top 100 Interview Questions and Answers on React JS & Redux, covering key concepts, state management, and best practices.

 

  1. What is React?

React is a JavaScript library for building user interfaces, particularly single-page applications (SPAs). It uses a component-based architecture and a virtual DOM for efficient updates.

 

  1. What are the key features of React?

Component-based, Virtual DOM, JSX, Unidirectional data flow, and Declarative UI.

 

  1. What is JSX?

JSX is a syntax extension for JavaScript that allows you to write HTML-like code in JavaScript. It gets transpiled to React.createElement() calls.

 

  1. What is the difference between JSX and HTML?

JSX is JavaScript, so it uses className instead of class, and htmlFor instead of for. It also allows embedding JavaScript expressions inside curly braces {}.

 

  1. What is the Virtual DOM?

The Virtual DOM is a lightweight copy of the real DOM. React uses it to optimize updates by comparing the Virtual DOM with the real DOM and applying only the necessary changes.

 

  1. What are the components of React?

Components are reusable, self-contained pieces of code that return JSX to render UI elements. They can be functional or class-based.

 

  1. What is the difference between functional and class components?

Functional components are plain JavaScript functions that return JSX. Class components are ES6 classes that extend React. Component and have lifecycle methods.

 

  1. What are props in React?

Props (short for properties) are read-only inputs passed to a component. They allow data to flow from a parent component to a child component.

 

  1. What is a state in React?

State is a built-in React object used to store data or information about the component. It is mutable and can be updated using setState() in class components or the useState hook in functional components.

 

  1. What is the difference between state and props?

The state is internal and controlled by the component itself, while props are external and controlled by the parent component.

 

React Hooks

  1. What are React hooks?

Hooks are functions that let you use state and other React features in functional components. Examples: useState, useEffect, useContext.

 

  1. What is the useState hook?

useState is a hook that allows functional components to manage state. It returns an array with the current state value and a function to update it.

 

  1. What is the useEffect hook?

useEffect is used to perform side effects in functional components, such as fetching data, updating the DOM, or subscribing to events.

 

  1. What is the purpose of the dependency array in useEffect?

The dependency array specifies when the effect should run. If the array is empty, the effect runs only once. If it contains values, the effect runs when those values change.

 

  1. What is the useContext hook?

useContext allows you to consume context in a functional component without wrapping it in a Context.Consumer.

 

  1. What is the useReducer hook?

useReducer is an alternative to useState for managing complex state logic. It takes a reducer function and an initial state, returning the current state and a dispatch function.

 

  1. What is the difference between useState and useReducer?

useState is simpler and better for basic state management, while useReducer is better for complex state logic or when the next state depends on the previous one.

 

  1. What is the useRef hook?

useRef returns a mutable object with a .current property. It is used to access DOM elements or store mutable values that don’t trigger re-renders.

 

  1. What is the useMemo hook?

useMemo is used to memoize expensive calculations so they are only recomputed when their dependencies change.

 

  1. What is the useCallback hook?

useCallback is used to memoize functions so they are only recreated when their dependencies change.

 

React Lifecycle Methods

  1. What are the lifecycle methods in React?

Lifecycle methods are special methods in class components that run at specific stages of a component’s life, such as mounting, updating, and unmounting.

 

  1. What is componentDidMount?

componentDidMount is a lifecycle method that runs after a component is mounted (inserted into the DOM).

 

  1. What is componentDidUpdate?

componentDidUpdate is a lifecycle method that runs after a component’s state or props are updated.

 

  1. What is componentWillUnmount?

componentWillUnmount is a lifecycle method that runs before a component is removed from the DOM.

 

  1. What is the equivalent of componentDidMount in functional components?

The useEffect hook with an empty dependency array.

 

  1. What is the equivalent of componentDidUpdate in functional components?

The useEffect hook with dependencies in the dependency array.

 

  1. What is the equivalent of componentWillUnmount in functional components?

The cleanup function is returned by the useEffect hook.

 

State Management

  1. What is Redux?

Redux is a state management library for JavaScript applications. It uses a single global store to manage application state.

 

  1. What are the three principles of Redux?

Single source of truth, state is read-only, and changes are made with pure functions (reducers).

 

  1. What is a reducer in Redux?

A reducer is a pure function that takes the current state and an action and returns the new state.

  1. What is an action in Redux?

An action is a plain JavaScript object that describes what happened. It must have a type property.

 

  1. What is the difference between Redux and Context API?

Redux is a standalone library with middleware and dev tools, while Context API is built into React and is simpler for small applications.

 

  1. What is React Query?

React Query is a library for managing server state, caching, and data fetching in React applications.

 

  1. What is Zustand?

Zustand is a lightweight state management library for React.

 

Advanced React Concepts

  1. What are Higher-Order Components (HOCs)?

HOCs are functions that take a component and return a new component with additional props or behavior.

 

  1. What are render props?

Render props is a pattern where a component’s prop is a function that returns JSX.

 

  1. What is React.memo?

React.memo is a higher-order component that memoizes a functional component to prevent unnecessary re-renders.

 

  1. What is the difference between React.memo and useMemo?

React.memo memoizes a component, while useMemo memoizes a value.

 

  1. What is code splitting in React?

Code splitting is a technique to split your code into smaller bundles that are loaded on demand, improving performance.

 

  1. What is lazy loading in React?

Lazy loading is a technique to load components only when they are needed, using React.lazy and Suspense.

 

For Free Demo classes Call: 8237077325

Registration Link: React JS Classes in Pune!

 

React Router

  1. What is React Router?

React Router is a library for routing in React applications.

 

  1. What is the difference between BrowserRouter and HashRouter?

BrowserRouter uses the HTML5 history API, while HashRouter uses the hash portion of the URL.

 

  1. What is the useNavigate hook?

useNavigate is a hook that returns a function to programmatically navigate to different routes.

 

  1. What is the useParams hook?

useParams is a hook that returns an object of key-value pairs from the URL parameters.

 

  1. What is the useLocation hook?

useLocation is a hook that returns the current location object.

 

  1. How do you optimize React performance?

Use React.memo, useMemo, useCallback, code splitting, lazy loading, and avoid unnecessary re-renders.

 

  1. What is the purpose of keys in React lists?

Keys help React identify which items have changed, been added, or been removed, improving rendering performance.

 

  1. What is the significance of shouldComponentUpdate?

shouldComponentUpdate is a lifecycle method that allows you to control whether a component should re-render.

 

  1. What is the difference between PureComponent and Component?

PureComponent implements a shallow comparison of props and state, preventing unnecessary re-renders.

 

  1. What is the purpose of React.Fragment?

React.Fragment allows you to group multiple elements without adding an extra node to the DOM.

  1. How do you test React components?

Use Jest with React Testing Library or Enzyme to write unit and integration tests.

 

  1. What is the significance of the key in React?

Keys help React identify which items have changed, been added, or been removed from a list.

 

  1. What is the difference between controlled and uncontrolled components?

Controlled components have their state managed by React, while uncontrolled components manage their own state using refs.

 

  1. What is the purpose of ref in React?

ref is used to access DOM elements or store mutable values.

 

  1. What is the difference between createElement and cloneElement?

createElement creates a new element, while cloneElement clones an existing element and allows you to add new props.

 

  1. What is the purpose of React.StrictMode?

React.StrictMode is a tool for highlighting potential problems in your application during development.

 

  1. What is the difference between ReactDOM.render and ReactDOM.createRoot?

ReactDOM.createRoot is used in React 18 for concurrent rendering, while ReactDOM.render is the legacy API.

 

Advanced React Concepts (Continued)

  1. What is the Context API?

The Context API is a built-in React feature for sharing data (like themes or authentication) across the component tree without passing props manually.

 

  1. What is the difference between useContext and Redux?

useContext is simpler and built into React, while Redux is a standalone library with middleware and dev tools for complex state management.

 

  1. What is the purpose of React.forwardRef?

React.forwardRef allows you to pass a ref from a parent component to a child component.

 

  1. What is the difference between useImperativeHandle and forwardRef?

forwardRef passes the ref to the child component, while useImperativeHandle customizes the instance value exposed to the parent component.

 

  1. What is the purpose of React.lazy?

React.lazy is used to lazily load components, improving performance by loading them only when needed.

  1. What is Suspense in React?

Suspense is a component that lets you display a fallback (like a loading spinner) while waiting for lazy components or data to load.

 

  1. What is the error boundary in React?

Error boundaries are React components that catch JavaScript errors in their child component tree and display a fallback UI.

 

  1. How do you create an error boundary?

By defining a class component with static getDerivedStateFromError() or componentDidCatch() lifecycle methods.

 

  1. What is the purpose of React.PureComponent?

React.PureComponent performs a shallow comparison of props and states to prevent unnecessary re-renders.

 

  1. What is the difference between React.memo and React.PureComponent?

React.memo is for functional components, while React.PureComponent is for class components.

 

React Router (Continued)

  1. What is the difference between Route and Switch?

Switch renders only the first matching Route, while without Switch, all matching routes are rendered.

 

  1. What is the purpose of useRouteMatch?

useRouteMatch is a hook that returns match information about the current route.

 

  1. What is the difference between Link and NavLink?

NavLink adds an active class to the link when it matches the current route, while Link does not.

 

  1. What is the purpose of Redirect in React Router?

Redirect is used to navigate to a different route programmatically.

 

  1. What is the difference between HashRouter and MemoryRouter?

HashRouter uses the hash portion of the URL, while MemoryRouter keeps the URL in memory (useful for testing).

 

State Management (Continued)

  1. What is Redux Thunk?

Redux Thunk is middleware that allows you to write action creators that return functions instead of actions, enabling asynchronous logic.

 

  1. What is Redux Saga?

Redux Saga is middleware that uses generators to handle side effects like asynchronous actions.

 

  1. What is the difference between Redux Thunk and Redux Saga?

Redux Thunk is simpler and uses functions, while Redux Saga is more powerful and uses generators.

 

  1. What is the purpose of combineReducers in Redux?

combineReducers combines multiple reducers into a single reducer function.

 

  1. What is the purpose of mapStateToProps and mapDispatchToProps?

mapStateToProps maps Redux state to component props, while mapDispatchToProps maps action creators to props.

 

Performance Optimization (Continued)

  1. What is the purpose of React.memo?

React.memo memoizes a functional component to prevent unnecessary re-renders.

 

  1. What is the difference between React.memo and useMemo?

React.memo memoizes a component, while useMemo memoizes a value.

 

  1. What is the purpose of useCallback?

useCallback memoizes a function to prevent unnecessary recreations.

 

  1. What is the purpose of React.lazy and Suspense?

React.lazy lazily loads components, and Suspense displays a fallback while waiting for the component to load.

 

  1. What is the purpose of React.Fragment?

React.Fragment allows you to group multiple elements without adding an extra node to the DOM.

 

Testing in React (Continued)

  1. What is the purpose of jest.mock?

jest.mock is used to mock modules or functions in Jest tests.

 

  1. What is the purpose of rendering in the React Testing Library?

render renders a React component for testing.

 

  1. What is the purpose of fireEvent in the React Testing Library?

fireEvent simulates user interactions like clicks or input changes.

 

  1. What is the purpose of the screen in React Testing Library?

screen provides methods to query the rendered DOM.

 

  1. What is the difference between shallow and mount in Enzyme?

shallow renders only the component, while mount renders the component and its children.

 

  1. What is the purpose of ReactDOM.createPortal?

ReactDOM.createPortal renders a component outside its parent DOM hierarchy.

 

  1. What is the purpose of React.Children?

React.Children provide utilities for working with props.children.

 

  1. What is the purpose of React.cloneElement?

React.cloneElement clones a React element and allows you to add new props.

 

  1. What is the purpose of React.isValidElement?

React.isValidElement checks if an object is a valid React element.

 

  1. What is the purpose of ReactDOM.findDOMNode?

ReactDOM.findDOMNode returns the DOM node associated with a class component.

 

  1. What is the purpose of ReactDOM.unmountComponentAtNode?

ReactDOM.unmountComponentAtNode unmounts a React component from the DOM.

 

  1. What is the purpose of ReactDOM.hydrate?

ReactDOM.hydrate is used to attach event listeners to server-rendered HTML.

 

  1. What is the purpose of ReactDOMServer?

ReactDOMServer is used to render React components to static HTML on the server.

 

  1. What is the purpose of React.StrictMode?

React.StrictMode highlights potential problems in your application during development.

 

  1. What is the difference between ReactDOM.render and ReactDOM.createRoot?

ReactDOM.createRoot is used in React 18 for concurrent rendering, while ReactDOM.render is the legacy API.

 

Do watch the latest video on Java: Click Here 

Author:-

Sonal Vanarse

Call the Trainer and Book your free demo Class For JavaScript Call now!!!
| SevenMentor Pvt Ltd.

© Copyright 2021 | SevenMentor Pvt Ltd.