Popular Searches
Popular Course Categories
Popular Courses

Top 50 React JS Interview Questions and Answers for Freshers (2026)

What Our Students Say
React JS Interview Questions and Answers for Beginners

Prepare for your React developer interview with the top 50 React JS interview questions and answers for freshers. Learn React basics, hooks, components, state, props, and more.

1. What is React?

React is a JavaScript library developed by Facebook (Meta) used for building user interfaces, mainly single-page applications. React allows developers to create reusable UI components and update the UI efficiently using a Virtual DOM instead of directly manipulating the real DOM. This improves performance and user experience.

👉 Explore the complete React Js course details:
https://www.justacademy.co/course-detail/flutter-training

👉 Also Available as Online Training Major Cities in India

React JS Training in Mumbai | Hands-On Offline Coding & Placement Support | JustAcademy

React Online Learning Course in Delhi | React Developer Training

Online React JS Training in Hyderabad – Live Interactive Classes by JustAcademy

best mobile app testing using react js training institutes for working professionals in chennai

React JS Online Training in Pune | Career-Focused Training | JustAcademy

best mobile app testing using react js training institutes for working professionals in ahmedabad

Key Points:

  • JavaScript UI library
     
  • Component-based
     
  • Uses Virtual DOM
     
  • Fast and scalable
     

Example:

function App() {

  return <h1>Hello React</h1>;

}

2. Why is React used?

React is used because it makes frontend development faster, cleaner, and more maintainable. It allows reusable components, efficient UI updates, and easy integration with backend APIs like Node.js.

Key Points:

  • Reusable components
     
  • Easy state management
     
  • Strong community
     
  • High demand in jobs
     

Example:
Same button component reused on multiple pages.

3. What is a Single Page Application (SPA)?

A Single Page Application loads only one HTML page, and content updates dynamically without page reloads. React is ideal for SPAs because it updates only required UI parts using state and routing.

Key Points:

  • No full page reload
     
  • Faster navigation
     
  • Better UX
     

Example:
Login → Dashboard without refresh.

4. What is a component in React?

A component is an independent, reusable part of the UI. Each component handles its own structure and logic. React applications are built by combining many small components.

Key Points:

  • Reusable UI blocks
     
  • Improves maintainability
     
  • Functional components preferred
     

Example:

function Header() {

  return <h2>Welcome</h2>;

}

5. What is JSX?

JSX stands for JavaScript XML. It allows writing HTML-like code inside JavaScript. JSX improves readability and helps structure UI easily.

Key Points:

  • Looks like HTML
     
  • Converted to JS by Babel
     
  • Not compulsory but recommended
     

Example:

const element = <h1>Hello</h1>;

6. Is JSX compulsory?

JSX is not compulsory, but without JSX code becomes complex and harder to read. JSX makes React development faster and cleaner.

Example (without JSX):

React.createElement("h1", null, "Hello");

7. What is Virtual DOM?

Virtual DOM is a lightweight copy of the real DOM. React first updates the Virtual DOM, compares changes, and updates only changed elements in the real DOM. This improves performance.

Key Points:

  • Faster updates
     
  • Less DOM manipulation
     
  • Efficient rendering
     

Example:
Only counter value updates, not full page.

8. What is state in React?

State is an object that stores dynamic data inside a component. When state changes, React automatically re-renders the component.

Key Points:

  • Mutable
     
  • Local to component
     
  • Causes re-render
     

Example:

const [count, setCount] = useState(0);

9. What are props in React?

Props are used to pass data from parent to child components. Props are read-only and help make components reusable.

Key Points:

  • One-way data flow
     
  • Immutable
     
  • Passed from parent
     

Example:

<Profile name="Rajan" />

10. Difference between state and props

State is local and changeable, while props are external and read-only. State is managed by the component itself, props are controlled by parent components.

11. What is useState hook?

useState is a React Hook that allows functional components to manage state. It returns the current state and a function to update it.

Example:

const [name, setName] = useState("Rajan");

12. Why were hooks introduced?

Hooks were introduced to:

  • Use state in functional components
     
  • Remove class component complexity
     
  • Reuse logic easily
     

13. What is useEffect hook?

useEffect is used to handle side effects like API calls, timers, and subscriptions.

Example:

useEffect(() => {

  fetchData();

}, []);

14. What is dependency array in useEffect?

The dependency array controls when useEffect runs.

Cases:

  • [] → runs once
     
  • [state] → runs on state change
     

15. What is conditional rendering?

Conditional rendering means showing UI based on conditions like login status.

Example:

{isLoggedIn ? <Dashboard /> : <Login />}

16. What is list rendering?

List rendering in React means displaying multiple items on the screen using an array of data.

When we have data like a list of names, products, or tasks, React allows us to loop through that data and show each item in the UI. This is usually done using the map() method. For every item in the array, React creates a JSX element.

Example:

const names = ["Rohan", "Amit", "Neha"];

function NameList() {

  return (

    <ul>

      {names.map((name, index) => (

        <li key={index}>{name}</li>

      ))}

    </ul>

  );

}

17. What is key in React?

A key in React is a special attribute used when rendering lists. It helps React identify each item uniquely in a list so it can update the UI efficiently.

When React renders a list, it needs to know which items are added, removed, or changed. The key tells React exactly which element is which.

Example:

const users = [

  { id: 1, name: "Amit" },

  { id: 2, name: "Neha" },

  { id: 3, name: "Rohan" }

];

function UserList() {

  return (

    <ul>

      {users.map(user => (

        <li key={user.id}>{user.name}</li>

      ))}

    </ul>

  );

}

18. What is a controlled component?

A controlled component in React is a form element whose value is controlled by React state.

This means the input field (like input, textarea, or select) does not manage its own data. Instead, React stores the value in state and updates it using an event handler.

Example:

import { useState } from "react";

function LoginForm() {

  const [email, setEmail] = useState("");

  return (

    <input

      type="email"

      value={email}

      onChange={(e) => setEmail(e.target.value)}

    />

  );

}

19. What is an uncontrolled component?

An uncontrolled component in React is a form element that manages its own state using the DOM, not React state.

Instead of controlling the input value with useState, React accesses the value only when needed using a ref.

Example:

import { useRef } from "react";

function LoginForm() {

  const emailRef = useRef();

  const handleSubmit = () => {

    console.log(emailRef.current.value);

  };

  return (

    <>

      <input type="email" ref={emailRef} />

      <button onClick={handleSubmit}>Submit</button>

    </>

  );

}

20. What is lifting state up?

Lifting state up is a concept in React where state is moved from a child component to a common parent component so that multiple components can share the same data.

When two or more child components need to use or update the same data, keeping state in one child can cause problems. To solve this, the state is placed in their nearest common parent, and then passed down using props.

Example:

function Parent() {

  const [count, setCount] = useState(0);

  return (

    <>

      <ChildA count={count} />

      <ChildB setCount={setCount} />

    </>

  );

}

function ChildA({ count }) {

  return <h2>{count}</h2>;

}

function ChildB({ setCount }) {

  return <button onClick={() => setCount(prev => prev + 1)}>Increase</button>;

}

21. What is React Router?

React Router is a library used in React to manage navigation and routing in single-page applications.

It allows us to create multiple pages (like Home, About, Contact) in a React app without reloading the browser. React Router changes the UI based on the URL path, while the app runs on a single page.

Key Points:

  • Used for client-side routing
     
  • Loads components dynamically
     
  • Improves user experience by avoiding page refresh
     

Example:

import { BrowserRouter, Routes, Route } from "react-router-dom";

 

function App() {

  return (

    <BrowserRouter>

      <Routes>

        <Route path="/" element={<Home />} />

        <Route path="/about" element={<About />} />

      </Routes>

    </BrowserRouter>

  );

}

22. What is useParams?

useParams is a hook in React Router that lets you access dynamic URL parameters in a component.

When you define a route with a variable (like :id), useParams helps you get that value.

Example:
 import { useParams } from "react-router-dom";

 

function User() {

  const { id } = useParams();

  return <h2>User ID: {id}</h2>;

}

 

// Route

<Route path="/user/:id" element={<User />} />

23. What is useNavigate?

is a hook in React Router used to programmatically navigate between routes in a React app.

Short Example:

import { useNavigate } from "react-router-dom";

function Home() {

  const navigate = useNavigate();

 

  const goToAbout = () => {

    navigate("/about");

  };

 

  return <button onClick={goToAbout}>Go to About</button>;

}

// Route

<Route path="/about" element={<About />} />

24. What is prop drilling?

Prop drilling is a concept in React that happens when you pass data (props) from a parent component down to a child component, and then to a grandchild component, and so on, even if some intermediate components don’t need that data. It’s basically “drilling” props through multiple layers of components just so the deepest component can use them.

Explanation in simple terms:

  • Imagine you have a family tree of components: Grandparent → Parent → Child.
     
  • You have some data in the Grandparent that the Child needs.
     
  • To get that data to the Child, you pass it through the Parent, even if the Parent doesn’t need it. That’s prop drilling.

25. What is Context API?

The Context API in React is a way to share data globally across components without having to pass props manually at every level. It helps solve the prop drilling problem.

Explanation in simple terms:

  • Normally, data flows top-down via props.
     
  • With Context, you can create a central store for certain data (like theme, user info, language, etc.).
     
  • Any component within the context can access the data directly, without passing it through intermediate components.
     

26. What is Redux?

Redux is a state management library for JavaScript apps, commonly used with React. It helps manage the application state in a centralized store, making state predictable, easier to debug, and shareable across components.

Explanation in simple terms:

  • In React, state is usually local to a component.
     
  • When many components need the same data, passing it through props (prop drilling) or using Context API can become tricky.
     
  • Redux solves this by keeping all the state in a single central store.
     
  • Components can read state from the store and dispatch actions to update it.
     

27. Why Redux is needed?

Redux is needed in React (or any frontend app) when your application has complex state that needs to be shared across multiple components. It helps manage state in a predictable, centralized, and maintainable way.

28. What is Redux Toolkit?

Redux Toolkit (RTK) is the official, recommended way to write Redux logic. It simplifies Redux by reducing boilerplate code and providing useful utilities for common Redux tasks.

Why Redux Toolkit?

Traditional Redux can be verbose and require writing a lot of boilerplate code:

  • Actions
     
  • Action types
     
  • Reducers
     
  • Dispatching logic
     

Redux Toolkit makes this easier and faster with built-in utilities.

29. What is useSelector?

In React-Redux, the useSelector hook is used to read data from the Redux store in a functional component. It lets your component subscribe to the store and get the piece of state it needs.

Explanation in simple terms:

  • Think of useSelector as a way for a component to “select”” the state it needs from the global Redux store.
     
  • Whenever the selected state changes, the component re-renders automatically.

30. What is useDispatch?

In React-Redux, the useDispatch hook is used to send actions to the Redux store. It lets your component update the state by dispatching actions created in your reducers or slices.

Explanation in simple terms:

  • Think of useDispatch as a way for a component to “tell Redux to change the state”.
     
  • You dispatch an action, and Redux uses a reducer to update the store based on that action.
     

Syntax:

const dispatch = useDispatch();

dispatch(action());

31. What is Fragment?

In React, a Fragment is a component that lets you group multiple elements together without adding extra nodes to the DOM. It’s useful when a component needs to return multiple elements but you don’t want unnecessary <div> wrappers.

Explanation in simple terms:

  • Normally, React components must return a single parent element.
     
  • Without Fragment, you might wrap elements in a <div> just to satisfy this rule.
     
  • Fragment allows you to wrap elements invisibly, without affecting the HTML structure.
     

32. What is React.memo?

React.memo is a higher-order component in React that is used to optimize functional components by preventing unnecessary re-renders when the component’s props have not changed.

Explanation in simple terms:

  • Normally, React re-renders a component whenever its parent re-renders, even if the props didn’t change.
     
  • React.memo memorizes the rendered output of a component.
     
  • If the props are the same as the previous render, React skips re-rendering that component.
     

Syntax:

const MemoizedComponent = React.memo(Component);

33. What is useCallback?

In React, useCallback is a hook that returns a memoized version of a function, which doesn’t change between re-renders unless its dependencies change. It is mainly used to optimize performance by preventing unnecessary re-creation of functions.

Explanation in simple terms:

  • In React, every render creates new functions.
     
  • If you pass these functions as props to child components, it can cause unnecessary re-renders, especially if the child uses React.memo.
     
  • useCallback remembers the function and returns the same function instance unless dependencies change.

34. What is useMemo?

n React, useMemo is a hook that memoizes the result of a computation so that it is recalculated only when its dependencies change. It helps optimize performance by avoiding expensive calculations on every render.

Explanation in simple terms:

  • Sometimes, a component does a heavy calculation during rendering.
     
  • Without useMemo, the calculation runs on every render, even if the inputs haven’t changed.
     
  • useMemo remembers the result of the calculation and reuses it unless dependencies change.

35. What is lazy loading?

Lazy Loading in React (and web development in general) is a technique where you load components, images, or other resources only when they are needed, instead of loading everything upfront. This improves performance and reduces the initial load time of your app.

Explanation in simple terms:

  • Normally, a React app loads all components at once, even if some are not visible immediately.
     
  • With lazy loading, components are loaded “on demand”, i.e., only when they are rendered or needed.
     
  • This is especially useful for large apps with many pages or heavy components.

     

36. What is error boundary?

In React, an Error Boundary is a special type of component that catches JavaScript errors anywhere in its child component tree, logs them, and displays a fallback UI instead of crashing the whole app.

37. What is reconciliation?

Reconciliation is the process by which React updates only the changed parts of the UI efficiently using the virtual DOM.

Key Points:

  • React keeps a virtual DOM (a lightweight copy of the real DOM).
     
  • When state or props change, React compares the new virtual DOM with the old one.
     
  • Only the differences are updated in the real DOM.
     
  • This makes the app faster and smoother.

38. How does event handling work in React?

In React, events like clicks, form submissions, or keyboard inputs are handled differently from plain HTML. React uses synthetic events, which are cross-browser wrappers around the native events. This ensures that events behave consistently across all browsers.

Unlike HTML, React events are written in camelCase instead of lowercase, and you pass a function as the event handler instead of a string. For example, in HTML you might write <button onclick="doSomething()">Click</button>, but in React it becomes <button onClick={doSomething}>Click</button>.

Key Points:

  • React uses camelCase for event names (onClick, onChange, onSubmit).
     
  • Event handlers are functions, not strings.
     
  • You can pass parameters to event handlers using arrow functions.
     
  • Synthetic events provide cross-browser consistency.
     
  • You can prevent default behavior using event.preventDefault() just like in HTML.
     

Example:

import React from "react";

function App() {

  const handleClick = () => {

    alert("Button clicked!");

  };

  const handleInput = (event) => {

    console.log("Input value:", event.target.value);

  };

  return (

    <div>

      <button onClick={handleClick}>Click Me</button>

      <input type="text" onChange={handleInput} placeholder="Type something" />

    </div>

  );

}

export default App;

39. onClick vs onclick

  • onClick → React
     
  • onclick → HTML
     

40. What is useRef?

useRef is a React hook that allows you to store a reference to a DOM element or a value that persists across renders without causing the component to re-render. It is often used to access DOM elements directly or to keep a mutable value that doesn’t trigger re-renders.

Key Points:

  • useRef returns a ref object with a .current property.
     
  • Useful for accessing DOM elements like input fields, buttons, or divs.
     
  • Can store any mutable value that should survive re-renders.
     
  • Updating .current does not trigger a re-render, unlike state.

41. What is forwardRef?

forwardRef is a React function that allows a parent component to pass a ref down to a child component, so the parent can directly access a DOM element or a child component’s instance. Normally, refs cannot be attached to functional components, but forwardRef solves this problem.

Key Points:

  • Used to pass refs through components.
     
  • Helps access child DOM elements from a parent.
     
  • Often used in reusable components like custom input fields, buttons, or modals.
     
  • Works only with functional components.
     

42. What is Strict Mode?

Strict Mode is a tool in React that helps you find potential problems in your application during development. It does not affect the production build; it only runs checks in development mode. Strict Mode helps developers write safer and more reliable code by highlighting unsafe lifecycles, deprecated APIs, and unexpected side effects.

Key Points:

  • Runs only in development, not in production.
     
  • Detects unsafe lifecycle methods in class components.
     
  • Helps find side effects or unexpected behavior in components.
     
  • Warns about deprecated APIs and legacy patterns.
     
  • Can wrap any part of your app to apply strict checks.

43. How are forms handled in React?

In React, forms are handled differently from plain HTML. Instead of letting the browser manage form data, React uses state to store input values. This approach is called a controlled component, where React state becomes the “single source of truth” for form inputs.

By controlling the inputs through state, you can easily validate, manipulate, or submit data in a predictable way. React also provides ways to handle uncontrolled components using refs, but controlled components are more common in React apps.

Key Points:

  • Controlled Components:

    • Input value is stored in React state.
       
    • Use value and onChange to control input.
       
  • Uncontrolled Components:

    • Input value is stored in the DOM.
       
    • Use useRef to access input values.
       
  • Form submission is handled using a function with onSubmit.
     
  • You can prevent default behavior using event.preventDefault().
     

44. How to call API in React?

In React, you often need to fetch data from external sources like REST APIs or backend servers. This is usually done using JavaScript functions like fetch or libraries like Axios. To make API calls at the right time in React, you typically use the useEffect hook for functional components.

Using useEffect ensures that the API call happens after the component has rendered. You can then store the response in the component’s state using useState, so the UI updates automatically when the data arrives.

Key Points:

  • Use useEffect to call APIs in functional components.
     
  • Use useState to store API response data.
     
  • API calls can be made using fetch or Axios.
     
  • Handle loading and error states to improve UX.
     

Example: Using fetch

import React, { useState, useEffect } from "react";

function App() {

  const [data, setData] = useState([]);

  const [loading, setLoading] = useState(true);

  const [error, setError] = useState(null);

 

  useEffect(() => {

    fetch("https://jsonplaceholder.typicode.com/posts")

      .then((response) => response.json())

      .then((json) => {

        setData(json);

        setLoading(false);

      })

      .catch((err) => {

        setError(err);

        setLoading(false);

      });

  }, []); // Empty dependency array means it runs once on mount

 

  if (loading) return <p>Loading...</p>;

  if (error) return <p>Error: {error.message}</p>;

 

  return (

    <div>

      <h1>Posts</h1>

      <ul>

        {data.map((post) => (

          <li key={post.id}>{post.title}</li>

        ))}

      </ul>

    </div>

  );

}

 

export default App;

45. What is defaultProps?

defaultProps is a feature in React that allows you to set default values for a component’s props. This is useful when a parent component does not pass certain props, so the component can still render correctly with predefined defaults.

Using defaultProps ensures that your component always has valid values, preventing errors or unexpected behavior.

46. Functional vs Class components

In React, there are two main ways to create components: Functional Components and Class Components. Both are used to render UI, but they differ in syntax, features, and how they handle state and lifecycle methods.

1. Functional Components

Functional components are JavaScript functions that return JSX. They are simpler and easier to write. Initially, they did not have state or lifecycle methods, but with the introduction of React Hooks (useState, useEffect), functional components can now manage state and side effects.

2. Class Components

Class components are ES6 classes that extend React.Component. They can have state and lifecycle methods without hooks. Class components are more verbose but were traditionally used for complex components.

47. What is HOC?

A Higher-Order Component (HOC) is a function in React that takes a component as input and returns a new enhanced component. HOCs are used to reuse logic, add functionality, or modify behavior of components without repeating code.

Think of it as a wrapper that adds extra features to an existing component. HOCs are commonly used for tasks like authentication, theming, logging, or data fetching

48. What is Pure Component?

A Pure Component in React is a class component that automatically implements a shallow comparison of props and state to decide whether it should re-render. If the props and state have not changed, a Pure Component skips re-rendering, which can improve performance for complex UIs.

Pure Components are useful when you want to avoid unnecessary re-renders and optimize your application, especially when dealing with large or frequently updating components.

49. What is hydration?

Hydration in React is the process of attaching event listeners and making a server-rendered HTML page interactive on the client side. This is mainly used in Server-Side Rendering (SSR), where the server sends a fully rendered HTML page to the browser, and React “hydrates” it to make it behave like a normal React app.

Without hydration, the server-rendered HTML is static. Hydration ensures that all React features like state, events, and interactivity work properly after the page loads.

50. Why choose React?

React is one of the most popular JavaScript libraries for building user interfaces. Developers choose React because it is fast, efficient, and flexible, making it ideal for building modern web applications. React’s main advantage is that it allows you to build reusable UI components and manage complex apps easily.

React uses a virtual DOM, which makes UI updates fast and efficient. It also has a large community, extensive libraries, and tools like React Router and Redux that make building web apps simpler. Additionally, React is widely used in big companies like Facebook, Instagram, and Netflix, making it a valuable skill for developers.

Key Points:

  • Component-Based Architecture: Build reusable UI components.
     
  • Fast Performance: Uses virtual DOM to update only changed parts of the UI.
     
  • Easy to Learn: JSX and simple concepts make it beginner-friendly.
     
  • Strong Community Support: Many tutorials, libraries, and tools available.
     
  • SEO-Friendly: With server-side rendering (e.g., Next.js), React apps can be indexed by search engines.
     
  • Flexible and Scalable: Can be used for small projects or large enterprise applications.
     

Example of Component Reuse

function Button({ text }) {

  return <button>{text}</button>;

}

 

function App() {

  return (

    <div>

      <Button text="Save" />

      <Button text="Cancel" />

      <Button text="Submit" />

    </div>

  );

}

 

 

 

 

Connect With Us
whatsapp