arrow_back Back to Curriculum
react

React.js

Core concepts of the most popular UI library including Hooks, Virtual DOM, and component lifecycles.

Interview Questions

25 Total
Q1.

What is the Virtual DOM and how does React use it?

Medium

The Virtual DOM is a lightweight in-memory representation of the real DOM. React compares the V-DOM with the real DOM (Diffing) and updates only the changed nodes (Reconciliation), making UI rendering much faster.

Q2.

Explain the difference between useEffect and useLayoutEffect.

Hard

`useEffect` runs asynchronously AFTER the browser has painted the DOM. `useLayoutEffect` runs synchronously immediately after DOM mutations but BEFORE the browser paints, which prevents visual flickering when measuring DOM nodes.

Q3.

How can you prevent a React component from unnecessary re-rendering?

Medium

You can use `React.memo` for component memoization, `useMemo` to cache expensive calculations, and `useCallback` to cache function references between renders.

Q4.

What is Prop Drilling and how do you solve it?

Easy

Prop drilling is passing data down multiple nested components unnecessarily. We solve it using the Context API, or state management libraries like Redux or Zustand.

Q5.

What is the difference between a controlled component and an uncontrolled component in React?

Easy

A controlled component is one that has its state managed by React, while an uncontrolled component has its state managed by the DOM. Controlled components are typically used for form elements.

Q6.

How do you optimize the performance of a React application?

Medium

Optimizing the performance of a React application can be achieved through techniques such as code splitting, memoization, and avoiding unnecessary re-renders by using the `shouldComponentUpdate` method.

Q7.

What is the purpose of the `useEffect` hook in React?

Easy

The `useEffect` hook is used to handle side effects in functional components, such as making API calls or setting timers.

Q8.

How do you handle errors in a React application?

Medium

Errors in a React application can be handled using error boundaries, which are components that catch and handle errors in their child components.

Q9.

What is the difference between a functional component and a class component in React?

Easy

A functional component is a pure function that takes props and returns JSX, while a class component is a class that extends the `React.Component` class and has its own state and lifecycle methods.

Q10.

How do you implement server-side rendering in a React application?

Hard

Server-side rendering in a React application can be implemented using a library such as Next.js, which allows you to render React components on the server.

Q11.

What is the purpose of the `useContext` hook in React?

Easy

The `useContext` hook is used to access context (shared state) in a React application.

Q12.

How do you handle authentication in a React application?

Medium

Authentication in a React application can be handled using a library such as React Auth, which provides a set of components and hooks for handling authentication.

Q13.

What is the difference between a higher-order component and a render prop in React?

Medium

A higher-order component is a function that takes a component as an argument and returns a new component, while a render prop is a function that is passed as a prop to a component and is used to render the component.

Q14.

How do you optimize the performance of a React application using memoization?

Medium

Memoization in a React application can be achieved using the `useMemo` hook, which allows you to memoize the result of a function so that it is only re-computed when the dependencies change.

Q15.

What is the purpose of the `useReducer` hook in React?

Easy

The `useReducer` hook is used to manage state in a React application by providing a reducer function that is used to update the state.

Q16.

How do you handle optimistic updates in a React application?

Medium

Optimistic updates in a React application can be handled by using a library such as React Query, which provides a set of hooks and components for handling optimistic updates.

Q17.

What is the difference between a synchronous and an asynchronous update in React?

Easy

A synchronous update in React is one that is handled immediately, while an asynchronous update is one that is handled after a delay, such as when making an API call.

Q18.

How do you implement pagination in a React application?

Medium

Pagination in a React application can be implemented by using a library such as React Paginate, which provides a set of components and hooks for handling pagination.

Q19.

What is the purpose of the `useState` hook in React?

Easy

The `useState` hook is used to manage state in a functional component by providing a way to add state to the component.

Q20.

How do you handle accessibility in a React application?

Medium

Accessibility in a React application can be handled by using a library such as React A11y, which provides a set of components and hooks for handling accessibility.

Q21.

What is the difference between a portal and a regular component in React?

Medium

A portal in React is a component that is rendered outside of the regular component tree, while a regular component is rendered inside the component tree.

Q22.

How do you implement internationalization in a React application?

Hard

Internationalization in a React application can be implemented by using a library such as React Intl, which provides a set of components and hooks for handling internationalization.

Q23.

What is the purpose of the `useCallback` hook in React?

Easy

The `useCallback` hook is used to memoize a function so that it is only re-computed when the dependencies change.

Q24.

How do you handle dynamic imports in a React application?

Medium

Dynamic imports in a React application can be handled using a library such as Webpack, which provides a way to dynamically import modules.

Q25.

What is the difference between a React fragment and a regular component?

Easy

A React fragment is a component that allows you to group multiple components together without adding an extra DOM element, while a regular component is a component that is rendered as a separate DOM element.