React Interview Questions and Answers: 44 Questions for Freshers

Quick answer: These 44 React interview questions and answers cover what is asked most in React developer, front-end developer and full stack interviews: React basics, components and props, state and hooks, lifecycle and effects, state management and routing, and performance and advanced topics. Key answers include short code examples.

Read each answer, then close the page and explain it aloud in two or three sentences. That is exactly what interviewers check.

Contents

1. React Basics Interview Questions

Q1. What is React?

React is an open-source JavaScript library from Meta for building user interfaces from reusable components. It updates the page efficiently when data changes and is widely used for single-page applications, and with React Native for mobile apps.

Q2. What are the main features of React?

Component-based structure, JSX syntax, a virtual DOM for efficient updates, one-way data flow, hooks for state and side effects, and a large ecosystem of libraries and tools.

Q3. What is JSX?

JSX is a syntax extension that lets you write HTML-like markup inside JavaScript. A build tool such as Babel or the compiler in Vite converts it into normal JavaScript function calls. Expressions go inside curly braces, and class is written as className.

const name = 'Asha';
const element = <h1 className="title">Hello, {name}</h1>;

Q4. What is the virtual DOM?

The virtual DOM is a lightweight JavaScript copy of the real DOM. When state changes, React creates a new virtual tree, compares it with the previous one (diffing), and updates only the parts of the real DOM that changed, which is called reconciliation.

Q5. What is the difference between a library and a framework, and which is React?

A framework provides the whole structure and calls your code; a library is a tool your code calls. React is a library focused on the view layer, so routing, data fetching and state management are added with other libraries or a framework such as Next.js.

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

Functional components are plain JavaScript functions that return JSX and use hooks for state and side effects. Class components extend React.Component and use this.state and lifecycle methods. Functional components with hooks are the modern standard.

Q7. What is a React component?

A component is an independent, reusable piece of UI, such as a button, form or page section. Component names start with a capital letter, and components can be nested inside each other.

function Welcome({ name }) {
  return <p>Welcome, {name}!</p>;
}
// usage
<Welcome name="Ravi" />

2. Props and State Interview Questions

Q8. What are props?

Props (properties) are inputs passed from a parent component to a child. They are read-only inside the child, which keeps data flow predictable.

Q9. What is state?

State is data owned by a component that can change over time, such as a form input or a counter. When state changes, React re-renders the component.

Q10. What is the difference between props and state?

Props are passed in from the parent and cannot be changed by the child. State is managed inside the component and can be updated with its setter function. Both trigger re-renders when they change.

Q11. What is prop drilling and how do you avoid it?

Prop drilling means passing props through many intermediate components that do not need them. Avoid it with the Context API, a state library such as Redux or Zustand, or by restructuring components.

Q12. What is lifting state up?

When two sibling components need the same data, move the state to their closest common parent and pass it down as props, together with functions to update it.

Q13. What are controlled and uncontrolled components?

In a controlled component, React state holds the input's value and onChange updates it. In an uncontrolled component, the DOM holds the value and you read it with a ref. Controlled inputs are usual for forms with validation.

function NameInput() {
  const [name, setName] = useState('');
  return <input value={name} onChange={e => setName(e.target.value)} />;
}

Q14. Why should state not be modified directly?

Changing state directly, such as state.items.push(x), does not tell React to re-render and can cause bugs. Always call the setter with a new value or new object, for example setItems([…items, x]).

3. Hooks Interview Questions

Q15. What are React hooks?

Hooks are functions that let functional components use React features such as state, side effects and context. Common hooks are useState, useEffect, useContext, useRef, useMemo, useCallback and useReducer.

Q16. What are the rules of hooks?

Call hooks only at the top level of a component or custom hook, never inside loops, conditions or nested functions, and only from React functions. This keeps the hook order the same on every render.

Q17. How does useState work?

useState returns the current value and a function to update it. Passing a function to the setter uses the latest value, which is safer when the new state depends on the old one.

const [count, setCount] = useState(0);
setCount(c => c + 1);

Q18. How does useEffect work?

useEffect runs side effects such as data fetching, subscriptions and timers after render. The dependency array controls when it runs: [] runs once after mount, [x] runs when x changes, and no array runs after every render. Returning a function cleans up.

useEffect(() => {
  const id = setInterval(() => setTime(new Date()), 1000);
  return () => clearInterval(id); // cleanup
}, []);

Q19. How do you fetch data in React?

Fetch inside useEffect and store the result in state, handling loading and error states. In real projects, libraries such as TanStack Query (React Query) or a framework's data loaders handle caching and refetching.

useEffect(() => {
  let ignore = false;
  fetch(`/api/users/${id}`)
    .then(r => r.json())
    .then(data => { if (!ignore) setUser(data); });
  return () => { ignore = true; };
}, [id]);

Q20. What is useRef used for?

useRef holds a mutable value that persists across renders without causing a re-render. It is used to access DOM elements, such as focusing an input, and to store values like timer IDs.

Q21. What is the difference between useMemo and useCallback?

useMemo caches the result of an expensive calculation until its dependencies change. useCallback caches a function definition, which is useful when passing callbacks to memoised child components.

Q22. What is useContext and the Context API?

Context lets you share data such as the theme, language or logged-in user across many components without passing props at every level. Create a context, wrap components in its Provider, and read the value with useContext.

Q23. When would you use useReducer instead of useState?

Use useReducer when state logic is complex, involves several related values, or the next state depends on the previous one in many ways, such as a shopping cart. It works like a small Redux store inside the component.

Q24. What are custom hooks?

Custom hooks are functions whose names start with use and that call other hooks, so you can reuse stateful logic, such as useFetch or useLocalStorage, across components.

Preparing for a React interview? We run live one-to-one classes and mock interviews in React, JavaScript and full stack development, arranged around your free time. Chat on WhatsApp.

4. Rendering and Performance Interview Questions

Q25. Why are keys important in lists?

Keys help React identify which items changed, were added or removed. Use a stable unique ID; using the array index as a key can cause bugs when the list is reordered or filtered.

{users.map(u => <li key={u.id}>{u.name}</li>)}

Q26. How do you render content conditionally?

Use an if statement before returning, the ternary operator, or && for simple cases.

{isLoggedIn ? <Dashboard /> : <Login />}
{error && <p className="error">{error}</p>}

Q27. What causes a component to re-render?

A component re-renders when its state changes, when its parent re-renders, or when a context value it uses changes.

Q28. What is React.memo?

React.memo wraps a component so it re-renders only when its props change, which helps when a parent re-renders often but the child's props stay the same.

Q29. How do you improve performance in a React app?

Avoid unnecessary re-renders with React.memo, useMemo and useCallback, keep state close to where it is used, split code with React.lazy and Suspense, virtualise long lists, optimise images, and measure with the React DevTools Profiler.

Q30. What are fragments?

Fragments (<>…</>) let a component return several elements without adding an extra div to the DOM.

Q31. What is StrictMode?

StrictMode is a development-only tool that highlights potential problems. It intentionally runs some functions and effects twice to help find side effects and missing cleanups.

Q32. What are error boundaries?

Error boundaries are components that catch JavaScript errors in their child tree during rendering and show a fallback UI instead of crashing the whole app. They are written as class components or with a library such as react-error-boundary.

Q33. What are portals?

Portals render a child into a different part of the DOM, such as directly under body, which is useful for modals, tooltips and pop-ups.

5. Routing, State Management and Forms Interview Questions

Q34. How does routing work in React?

React Router maps URLs to components so a single-page app can show different views without full page reloads, using components such as BrowserRouter, Routes, Route and Link, and hooks such as useNavigate and useParams.

Q35. What is Redux?

Redux is a state management library with a single store, actions that describe changes, and reducers that return the new state. Redux Toolkit is the recommended modern way to use it, with less boilerplate.

Q36. When should you use Redux or another state library?

Use it when many unrelated components share and update the same data, such as a cart, user session or complex dashboards. For small apps, useState and Context are often enough.

Q37. How do you handle forms in React?

Use controlled inputs with state for simple forms, and libraries such as React Hook Form with a schema validator such as Zod or Yup for larger forms with validation.

Q38. How do you call an API with authentication from React?

Store the token securely, preferably in an HTTP-only cookie set by the server, send requests with fetch or axios, handle 401 responses by redirecting to login, and never put secret keys in front-end code.

6. Advanced and Ecosystem Interview Questions

Q39. What is the difference between client-side rendering and server-side rendering?

In client-side rendering, the browser downloads JavaScript and builds the page, which can be slower for the first view and SEO. In server-side rendering, the server sends ready HTML, which improves first load and SEO. Frameworks such as Next.js support both.

Q40. What is Next.js?

Next.js is a React framework that adds file-based routing, server-side rendering, static generation, React Server Components, API routes and built-in optimisation.

Q41. What are React Server Components?

Server Components run only on the server, can read data directly, and send rendered output to the client without adding their code to the browser bundle. Client Components, marked with 'use client', handle interactivity.

Q42. What is the difference between React and Angular?

React is a UI library with JSX and one-way data flow, and you choose other libraries for routing and state. Angular is a complete framework from Google using TypeScript, with built-in routing, forms, dependency injection and two-way binding.

Q43. How do you test React components?

Use Jest or Vitest with React Testing Library to render components and test them the way a user interacts, by finding elements by text or role and firing events. Use Cypress or Playwright for end-to-end tests.

Q44. What is the difference between React and React Native?

React builds web interfaces that render to the browser DOM. React Native uses the same component and hook ideas to build native Android and iOS apps with native UI elements.

How to Prepare for a React Interview

  1. Know hooks deeply: useState, useEffect dependencies and custom hooks come up in every round.
  2. Explain rendering: virtual DOM, reconciliation and why keys matter.
  3. Practise live coding: a counter, a to-do list and a fetch-and-display component.
  4. Learn one state library: Redux Toolkit or Zustand, and when Context is enough.
  5. Build and deploy a project: and be ready to explain every component.

Next steps: revise JavaScript interview questions and Node.js interview questions for full stack roles, and see all subjects on our interview questions page.

Want a mentor for your preparation? We teach React, JavaScript and full stack development through live online classes arranged around your free time, with mock interviews before your placement. Message us on WhatsApp or email engineersrworld@gmail.com.

More interview preparation: see all interview questions, including Python, SQL, SQL query, Java, JavaScript, React, C++, .NET, Spring Boot, Node.js, DSA, OOPs, DBMS, operating system, networking, machine learning, data science, AI, Excel, Power BI, DevOps, manual testing, Selenium, cyber security and HR.

Frequently Asked Questions

Which React topics are most asked for freshers?

JSX, components, props versus state, useState and useEffect, keys in lists, controlled forms, the virtual DOM, and conditional rendering come up in almost every fresher interview.

Should I learn JavaScript before React?

Yes. Strong JavaScript basics, especially ES6 features, array methods, promises and async/await, make React much easier.

Is React good for getting a job in India?

Yes. React is one of the most requested front-end skills in Indian start-ups and IT companies, and pairs well with Node.js for full-stack roles.

How should I prepare for a React interview?

Build two or three projects, such as a to-do app with filters, a weather app using an API and a small e-commerce cart, and be ready to explain hooks and re-rendering with your own code.

Scroll to Top