React Developer

100+ React Developer Interview Questions and Answers

Updated 18 Jan 2025
search-icon

Q1. Covid Vaccination Distribution Problem

As the Government ramps up vaccination drives to combat the second wave of Covid-19, you are tasked with helping plan an effective vaccination schedule. Your goal is to ma...read more

Q2. Swap Two Numbers Problem Statement

Given two integers a and b, your task is to swap these numbers and output the swapped values.

Input:

The first line contains a single integer 't', representing the number of t...read more

React Developer Interview Questions and Answers for Freshers

illustration image

Q3. Triplets with Given Sum Problem

Given an array or list ARR consisting of N integers, your task is to identify all distinct triplets within the array that sum up to a specified number K.

Explanation:

A triplet i...read more

Frequently asked in,

Q4. Sort Array Problem Statement

Given an array consisting of 'N' positive integers where each integer is either 0, 1, or 2, your task is to sort the given array in non-decreasing order.

Input:

Each input starts wi...read more
Are these interview questions helpful?

Q5. Furthest Building You Can Reach

In this problem, Ninja prefers jumping over building roofs rather than walking through the streets. The heights of the buildings in his city are represented by an array HEIGHTS, ...read more

Q6. How do you connect a component to Redux store? Which function in Redux is used to connect to store? What are the parameters in connect?

Ans.

To connect a component to Redux store, we use the connect function from the react-redux library.

  • Import the connect function from react-redux.

  • Use the connect function to wrap the component and connect it to the Redux store.

  • The connect function takes two parameters: mapStateToProps and mapDispatchToProps.

  • mapStateToProps is a function that maps the state from the Redux store to the component's props.

  • mapDispatchToProps is an optional function that maps the dispatch function to th...read more

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q7. What are Hooks in React? Name the ones you have used in your project.

Ans.

Hooks are a feature introduced in React 16.8 that allow developers to use state and other React features in functional components.

  • useState() - for managing state in functional components

  • useEffect() - for performing side effects in functional components

  • useContext() - for accessing context in functional components

  • useReducer() - for managing complex state and actions in functional components

  • useCallback() - for memoizing functions in functional components

  • useMemo() - for memoizing...read more

Q8. Write a React Class component. Convert this Class to a Functional Component. How can you pass prop from parent to child component? Write code.

Ans.

Answer to a React Developer interview question about class and functional components and passing props.

  • Class component: class MyComponent extends React.Component {}

  • Functional component: const MyComponent = (props) => {}

  • Passing props from parent to child:

React Developer Jobs

Senior React Developer 7-12 years
S&P Global Inc.
4.2
Gurgaon / Gurugram
Cognizant Face To Face Walk-in Interview For React Developers 4-9 years
Cognizant
3.8
Hyderabad / Secunderabad
React Developer - Bangalore 5-10 years
Infosys
3.6
Hyderabad / Secunderabad

Q9. How do you avoid re-rendering of a component? With useEffect second parameter, should ComponentUpdate

Ans.

To avoid re-rendering, use shouldComponentUpdate or React.memo

  • Use shouldComponentUpdate to compare current and next props/state

  • Use React.memo to memoize functional components

  • Use useMemo to memoize expensive computations

  • Use useCallback to memoize event handlers

  • Use PureComponent for class components

Q10. What are the differences between functional and class components in React?
Ans.

Functional components are simpler and easier to test, while class components have more features and lifecycle methods.

  • Functional components are written as JavaScript functions, while class components are written as ES6 classes.

  • Functional components are stateless and do not have their own internal state, while class components can have state.

  • Functional components do not have lifecycle methods, while class components have lifecycle methods like componentDidMount and componentDi...read more

Q11. What are Higher Order Functions and Higher Order Components. Give examples.

Ans.

Higher Order Functions are functions that take other functions as arguments or return functions as their results.

  • Higher Order Functions can be used to create reusable code by abstracting common functionality into a separate function.

  • They can also be used to implement functional programming concepts like currying and composition.

  • Example: Array.prototype.map() is a higher order function that takes a callback function as an argument and applies it to each element of an array, re...read more

Q12. How does Event Loop works? What are Event Queue and Event Stack?

Ans.

Event Loop is a mechanism that allows JavaScript to handle asynchronous operations.

  • Event Loop is a continuous process that checks the Event Queue and moves events to the Event Stack.

  • Event Queue holds all the events that are waiting to be processed.

  • Event Stack holds the events that are currently being processed.

  • When the Event Stack is empty, the Event Loop checks the Event Queue for new events.

  • JavaScript uses Event Loop to handle asynchronous operations like setTimeout(), setI...read more

Q13. What are refs? How will you use it for getting input value? Explain with code.

Ans.

Refs are a way to access DOM nodes or React components directly. They can be used to get input values.

  • Refs provide a way to access DOM nodes or React components directly.

  • They are commonly used to get input values or trigger imperative animations.

  • Refs can be created using the `createRef()` method or by using a callback function.

  • To get the value of an input using refs, you can assign a ref to the input element and access its value property.

Q14. What is Context API in React? Is there a need to have an initial state in Context API?

Ans.

Context API is a way to share data between components without passing props down manually.

  • Context API provides a way to pass data through the component tree without having to pass props down manually at every level.

  • It is useful for sharing data that needs to be accessed by many components at different levels of the tree.

  • Initial state can be set in Context API using the createContext() function.

  • There is no need to have an initial state in Context API, but it can be useful in s...read more

Q15. How can we structure the top-level directories in Redux?

Q16. What are the ways to handle Errors in React?

Ans.

Error handling in React can be done using try-catch blocks, error boundaries, and handling asynchronous errors.

  • Use try-catch blocks to handle synchronous errors

  • Use error boundaries to catch errors in child components

  • Handle asynchronous errors using promises or async/await

  • Use third-party libraries like Sentry or Bugsnag for better error tracking

  • Display user-friendly error messages to improve user experience

Q17. What is the minimum coverage for an app? How much code do you push to production/master branch while deployment?

Ans.

Minimum coverage for an app and code pushed to production/master branch while deployment.

  • Minimum coverage for an app depends on the project requirements and complexity.

  • Generally, a coverage of 80% or higher is considered good.

  • Code pushed to production/master branch should be thoroughly tested and reviewed.

  • Continuous integration and deployment can help automate this process.

  • Examples of tools for code coverage include Jest, Istanbul, and Enzyme.

Q18. What are export types in ReactJS?

Ans.

Export types in ReactJS allow components, functions, and variables to be accessed and used in other files.

  • Exporting a component allows it to be imported and used in other files

  • Exporting a function allows it to be imported and used in other files

  • Exporting a variable allows it to be imported and used in other files

Q19. How do you hide API URLs? How to manage different URLs for different staging environment?

Ans.

API URLs can be hidden by using environment variables and managing different URLs for different staging environments.

  • Use environment variables to store API URLs

  • Create separate environment files for different staging environments

  • Set the appropriate API URL in the environment file for each staging environment

  • Access the API URL from the environment variable in the code

Q20. Do Reducer need to have an initial state compulsorily?

Ans.

Yes, it is mandatory for Reducer to have an initial state.

  • Initial state defines the starting point of the state tree.

  • It helps in defining the shape of the state tree.

  • It is used to set default values for the state properties.

  • It is also used to reset the state to its initial values.

  • Example: const initialState = { count: 0 };

  • Example: const initialState = { name: '', age: 0 };

Q21. What are the differences between a class component and a functional component in ReactJS?
Q22. What are the states of a promise object in JavaScript?
Ans.

The states of a promise object are pending, fulfilled, or rejected.

  • A promise starts in the pending state.

  • When a promise is resolved, it transitions to the fulfilled state.

  • If a promise encounters an error, it transitions to the rejected state.

  • Once a promise is settled (fulfilled or rejected), it cannot transition to any other state.

Q23. What is React? Why do we use it? Make a form with 3 different child components and pass props from the parent. There should be Select box, an Input field and a Submit Button.

Ans.

React is a JavaScript library used for building user interfaces.

  • React allows for reusable components and efficient rendering.

  • It uses a virtual DOM to update only the necessary parts of the UI.

  • React is popular for its simplicity and flexibility.

  • Examples of companies using React include Facebook, Instagram, and Airbnb.

Q24. Explain Redux-Saga middleware. How do you Dispatch actions from components in Redux?

Ans.

Redux-Saga is a middleware for Redux that handles side effects. Actions can be dispatched from components using mapDispatchToProps.

  • Redux-Saga is used to handle side effects like API calls and asynchronous actions.

  • It uses generator functions to make asynchronous code look synchronous.

  • Sagas listen for specific actions and perform tasks based on those actions.

  • To dispatch actions from components, use mapDispatchToProps to connect the component to the Redux store.

  • Then call the act...read more

Q25. Will React re-render whole page or just a part of it?

Ans.

React re-renders just the part of the page that has changed, thanks to its virtual DOM.

  • React uses a virtual DOM to track changes in the UI.

  • When a component's state or props change, React compares the virtual DOM with the real DOM and updates only the necessary parts.

  • This approach improves performance by minimizing the number of DOM manipulations.

  • React's diffing algorithm efficiently determines the minimal set of changes needed to update the UI.

Q26. What is the difference between slice and splice in JavaScript?
Q27. Does a const variable make the value immutable in JavaScript?
Ans.

No, const does not make the value immutable.

  • const only makes the variable itself immutable, not the value it holds.

  • For objects and arrays, const prevents reassignment but allows mutation of properties or elements.

  • To make a value truly immutable, you can use Object.freeze() or other techniques.

Q28. How Promise works? What is Promise.all. Write code for both.

Ans.

Promises are a way to handle asynchronous operations in JavaScript. Promise.all is used to execute multiple promises concurrently.

  • Promises represent a value that may not be available yet

  • They have three states: pending, fulfilled, and rejected

  • Promise.all takes an array of promises and returns a new promise that resolves when all promises in the array have resolved

  • If any promise in the array is rejected, the returned promise is rejected with the reason of the first promise that...read more

Q29. What are Hooks in React? Explain useState, useEffect hooks.

Ans.

Hooks are functions that allow you to use state and other React features without writing a class.

  • useState is a hook that allows you to add state to functional components.

  • useEffect is a hook that allows you to perform side effects in functional components.

  • Hooks can only be used in functional components.

  • Hooks must be called at the top level of a functional component.

  • Hooks can be used to replace lifecycle methods in class components.

Q30. What are the differences between stateless and stateful components in ReactJS?
Q31. What is a first-class function in JavaScript?

Q32. Difference between Let, Const and Var. Write code and explain.

Ans.

Let, Const, and Var are used to declare variables in JavaScript with different scoping and reassignment abilities.

  • Var has function scope and can be redeclared and reassigned.

  • Let has block scope and can be reassigned but not redeclared.

  • Const has block scope and cannot be reassigned or redeclared.

Q33. How can you optimize a React App?

Ans.

Optimizing a React app involves reducing bundle size, using lazy loading, and optimizing rendering performance.

  • Reduce bundle size by code splitting and using dynamic imports

  • Use lazy loading to load components only when needed

  • Optimize rendering performance by using shouldComponentUpdate and PureComponent

  • Use React.memo to memoize functional components

  • Avoid unnecessary re-renders by using useMemo and useCallback

  • Use performance profiling tools like React DevTools and Chrome DevTo...read more

Q34. What are Hooks? What all Hooks have you used in your project?

Ans.

Hooks are functions that allow you to use state and other React features without writing a class.

  • useState() - for managing state in functional components

  • useEffect() - for performing side effects in functional components

  • useContext() - for consuming context in functional components

  • useReducer() - for managing complex state in functional components

  • useCallback() - for memoizing functions in functional components

  • useMemo() - for memoizing values in functional components

  • useRef() - fo...read more

Q35. How is Relay different from Redux?
Q36. What are the advantages of using Redux?

Q37. What is Lazy Loading, Suspense. How do they work?

Ans.

Lazy Loading and Suspense are techniques used to improve performance by loading components and data only when needed.

  • Lazy Loading delays the loading of non-critical resources until they are needed, reducing initial load time.

  • Suspense allows components to wait for data to load before rendering, improving user experience.

  • Lazy Loading and Suspense can be used together to optimize performance and user experience.

  • Example: A website with a large image gallery can use Lazy Loading t...read more

Q38. Can you explain promises in JavaScript and describe its three states?
Q39. What are the key differences between mapStateToProps() and mapDispatchToProps() in Redux?
Q40. What is a higher order function?

Q41. Features of ES6. Explain Spread Operator and Rest Parameter by writing code. Give example for Object Destructuring.

Ans.

ES6 features: Spread Operator, Rest Parameter, Object Destructuring

  • Spread Operator: allows an iterable to be expanded into individual elements

  • Rest Parameter: allows a function to accept an indefinite number of arguments as an array

  • Object Destructuring: allows extracting properties from an object and assigning them to variables

Q42. How to implement Responsiveness in App as per screen sizes?

Ans.

Responsiveness in app can be achieved using CSS media queries and responsive design principles.

  • Use CSS media queries to apply different styles based on screen sizes

  • Design the app layout to be flexible and adapt to different screen sizes

  • Use responsive units like percentages and viewport units for sizing elements

  • Test the app on different devices and screen sizes to ensure responsiveness

Q43. What is the significance of 'this' keyword in JS?

Ans.

The 'this' keyword in JS refers to the object that is currently executing the code.

  • The value of 'this' depends on how a function is called.

  • In a method, 'this' refers to the object that the method belongs to.

  • In a regular function, 'this' refers to the global object (window in a browser).

  • In an event handler, 'this' refers to the element that triggered the event.

  • The value of 'this' can be explicitly set using call(), apply(), or bind() methods.

Q44. How is state changed in Redux?
Q45. What are callbacks in JavaScript?
Q46. What is reconciliation in ReactJS?
Q47. What are custom hooks in React?
Ans.

Custom Hooks are reusable functions in React that allow you to extract logic from components.

  • Custom Hooks are functions that start with the word 'use' and can call other Hooks if needed.

  • They are used to share stateful logic between components without using higher-order components or render props.

  • Custom Hooks can be used to handle common tasks like fetching data, managing form state, or subscribing to events.

  • They promote code reusability and make it easier to separate concerns...read more

Q48. What are props in React?
Q49. What is the difference between TRUNCATE and DELETE in a database management system?
Q50. What is useState() in React?
Ans.

useState() is a React hook that allows functional components to manage state.

  • useState() is used to declare a state variable in a functional component.

  • It returns an array with two elements: the current state value and a function to update the state.

  • The initial state value is passed as an argument to useState().

  • The state can be updated by calling the update function returned by useState().

  • useState() can be used multiple times in a component to manage multiple state variables.

1
2
3
Next
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

3.7
 • 10.4k Interviews
3.8
 • 8.2k Interviews
3.6
 • 7.6k Interviews
3.8
 • 5.6k Interviews
3.7
 • 4.8k Interviews
3.5
 • 3.8k Interviews
4.0
 • 777 Interviews
3.8
 • 196 Interviews
3.6
 • 39 Interviews
View all

Calculate your in-hand salary

Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary

React Developer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter