IT Career Guide
Search

React Interview Questions: 35 Questions and Answers for Freshers

React code on a computer screen

React interview questions focus on components, state, hooks and rendering, and you can answer most of them well once you understand how React decides what to re-render. Below are 35 React interview questions that freshers and career switchers in India regularly meet in front-end and full stack interviews, with concise answers and small code examples.

Key takeaways

  • React is a JavaScript library for building user interfaces from reusable components.
  • Props pass data into a component, while state is data a component owns and can change.
  • Hooks such as useState, useEffect, useMemo and useRef are asked about in almost every React interview.
  • Keys help React match list items between renders, so they should be stable and unique, not array indexes when order can change.
  • Strong JavaScript fundamentals, especially closures, array methods and promises, make React answers much easier.

Before you start

React sits on top of JavaScript, so weak JavaScript shows up quickly in a React interview. Revise our JavaScript interview questions first if closures or promises feel shaky. If you are planning a full stack career, the full stack developer roadmap shows where React fits.

Basic React interview questions

1. What is React?

React is an open-source JavaScript library, maintained by Meta and the community, for building user interfaces. You describe the UI as a tree of components, and React updates the browser DOM efficiently when data changes.

2. What is JSX?

JSX is a syntax extension that lets you write HTML-like markup inside JavaScript. A build tool converts it into regular JavaScript function calls.

const greeting = <h1>Hello, {name}</h1>;

3. What is a component?

A component is a reusable piece of UI. In modern React it is simply a function that returns JSX. Component names must start with a capital letter.

function Welcome({ name }) {
  return <p>Welcome, {name}</p>;
}

4. What is the difference between props and state?

PropsState
Passed in by the parentOwned by the component
Read-only inside the componentChanged with a setter function
Used to configure a componentUsed for data that changes over time

5. What is the virtual DOM?

The virtual DOM is a lightweight in-memory description of the UI. When state changes, React builds a new description, compares it with the previous one and applies only the needed changes to the real DOM. This comparison is called reconciliation.

6. What are functional and class components?

Class components extend React.Component and use lifecycle methods. Functional components are plain functions and use hooks. New code is almost always written with functional components, but you may still see class components in older projects.

7. What is one-way data flow?

Data in React flows from parent to child through props. A child cannot change its parent’s data directly. Instead, the parent passes a callback function that the child calls.

8. What are keys and why are they important?

Keys are unique identifiers given to list items so React can tell which item changed, was added or was removed. Use a stable id from your data. Using the array index can cause bugs when items are reordered or deleted.

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

9. What is conditional rendering?

Conditional rendering means showing different UI depending on a condition, typically with the ternary operator or the logical AND operator.

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

10. What is a fragment?

A fragment lets a component return several elements without adding an extra wrapper div to the DOM. You write it as empty angle brackets.

React hooks interview questions

11. What are hooks?

Hooks are functions that let functional components use React features such as state and side effects. Their names start with use. They must be called at the top level of a component, not inside loops or conditions.

12. How does useState work?

useState returns the current value and a setter function. Calling the setter schedules a re-render with the new value.

const [count, setCount] = useState(0);
<button onClick={() => setCount(c => c + 1)}>{count}</button>

13. Why use the functional form of setState?

Passing a function such as c => c + 1 makes React use the latest value. This avoids bugs when several updates happen in the same event, because state updates are batched.

14. What does useEffect do?

useEffect runs side effects after render, such as fetching data, setting up subscriptions or changing the document title. The dependency array controls when it runs again, and the returned function cleans up.

useEffect(() => {
  const id = setInterval(tick, 1000);
  return () => clearInterval(id);
}, []);

15. What happens with an empty, missing or filled dependency array?

  • Empty array: the effect runs once after the first render.
  • No array: the effect runs after every render.
  • Array with values: the effect runs when any listed value changes.

16. What is the difference between useMemo and useCallback?

useMemo caches the result of a calculation between renders. useCallback caches a function definition. Both take a dependency array and are mainly used to avoid expensive work or unnecessary child re-renders.

17. What is useRef used for?

useRef stores a mutable value that survives re-renders without causing one. It is commonly used to access a DOM element directly, for example to focus an input.

18. What is the Context API?

Context lets you share data such as the logged-in user or theme with deeply nested components without passing props through every level. You create a context, wrap the tree in a Provider and read it with useContext.

19. What is useReducer and when should you use it?

useReducer manages state with a reducer function, similar to Redux. It suits state with several related values or complex update logic, such as a multi-step form.

20. What is a custom hook?

A custom hook is your own function, starting with use, that combines built-in hooks to reuse logic. For example, a useFetch hook can hold loading, error and data state for any API call.

Advanced React interview questions

21. What causes a component to re-render?

A component re-renders when its state changes, when its parent re-renders, or when a context it uses changes. Props changing is a result of the parent re-rendering.

22. What is React.memo?

React.memo wraps a component so it skips re-rendering when its props have not changed. It is useful for heavy components but adds a comparison cost, so do not wrap everything by default.

23. What are controlled and uncontrolled components?

In a controlled component, form input values live in React state and change through onChange. In an uncontrolled component, the DOM keeps the value and you read it with a ref. Controlled inputs make validation easier.

24. What is lifting state up?

When two sibling components need the same data, you move that state to their closest common parent and pass it down as props. This keeps a single source of truth.

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

Prop drilling is passing props through many layers that do not use them. You can avoid it with Context, a state library such as Redux Toolkit or Zustand, or by restructuring components.

26. What is code splitting and lazy loading?

Code splitting breaks the JavaScript bundle into smaller pieces that load on demand. React.lazy with Suspense loads a component only when it is first needed, which speeds up the initial page load.

27. What is an error boundary?

An error boundary is a component that catches JavaScript errors in its child tree during rendering and shows a fallback UI instead of a blank page. It is currently written as a class component or provided by a small library.

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

With client-side rendering, the browser downloads JavaScript and builds the page. With server-side rendering, the server sends ready HTML first, which helps first load speed and search engines. Frameworks such as Next.js add server rendering to React.

29. What is React Router?

React Router is a popular library for page navigation in single-page React apps. It maps URLs to components without a full page reload.

30. How would you fetch data from an API in React?

function Users() {
  const [users, setUsers] = useState([]);
  useEffect(() => {
    fetch('/api/users')
      .then(r => r.json())
      .then(setUsers);
  }, []);
  return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
}

In real projects, mention loading and error states, and libraries such as TanStack Query that handle caching and retries for you.

31. What is StrictMode?

StrictMode is a development-only wrapper that helps find problems early. It warns about unsafe patterns and, in development, runs some functions and effects twice to expose side effects that are not cleaned up properly. It has no effect on the production build.

32. Why should you not mutate state directly?

React decides whether to re-render by comparing references. If you change an array or object in place, the reference stays the same and React may not update the screen. Always create a new copy instead.

// wrong: items.push(newItem)
setItems(prev => [...prev, newItem]);
setUser(prev => ({ ...prev, city: 'Pune' }));

33. What are synthetic events?

React wraps native browser events in its own SyntheticEvent object so they behave consistently across browsers. You use them the same way, for example event.preventDefault() in an onSubmit handler.

34. What is a higher-order component?

A higher-order component is a function that takes a component and returns a new component with extra behaviour, such as adding authentication checks. Custom hooks have replaced many higher-order components in modern code, but you may still see them in older projects.

35. What are portals?

A portal renders a child component into a different part of the DOM, outside its parent’s element. Portals are commonly used for modals, tooltips and dropdowns that must appear above other content without being clipped by parent styles.

How to prepare for a React interview

Build two or three small projects rather than reading answers only. A to-do app teaches state and lists, a weather app teaches API calls and effects, and a small shopping cart teaches context and lifting state. If you want to go full stack, connect your React front end to a Node.js API, as explained in our MERN stack guide. Be ready to explain every line of your own code.

Frequently asked questions

Is React a framework or a library?

React is a library focused on the user interface. Frameworks such as Next.js build on React and add routing, server rendering and build tooling.

Are class components still asked in interviews?

Sometimes, mainly lifecycle methods like componentDidMount, because older codebases use them. Focus most of your preparation on functional components and hooks.

Should I learn Redux for a fresher React interview?

Learn the idea of a central store and Redux Toolkit basics. Many interviewers now accept Context or lighter state libraries for small apps.

How long does it take to prepare for React interviews?

If your JavaScript is solid, a few weeks of daily practice with small projects is usually enough to answer common React questions confidently.

Explore more guides in our full stack development section.

Other articles

Radium4 — IT training blog

Practical, plain-English guides for DevOps, cloud, data, Python, testing and security learners.