React & React Hooks Interview Questions (with Answers)
1. What is React?
React is a JavaScript library developed by Facebook for building user interfaces, especially for single-page
applications. It allows developers to build web applications that can update and render efficiently using
reusable components.
2. What is JSX?
JSX stands for JavaScript XML. It allows writing HTML structures in the same file as JavaScript code. React
uses JSX to describe the UI in a readable format.
3. What is the Virtual DOM?
The Virtual DOM is a lightweight JavaScript representation of the actual DOM. React uses it to optimize
rendering by updating only the parts of the DOM that changed.
4. What are components in React?
Components are the building blocks of a React application. There are two types: Functional Components and
Class Components. Functional components are preferred in modern React.
5. What is the difference between props and state?
Props are read-only attributes passed from parent to child components. State is a data structure that starts
with a default value when a component mounts and can be changed over time.
6. What are React Hooks?
Hooks are special functions introduced in React 16.8 that allow you to use state and lifecycle methods in
functional components. Examples include useState, useEffect, useContext, etc.
7. Explain useState with example.
useState is a hook that lets you add state to functional components.
Example:
const [count, setCount] = useState(0);
React & React Hooks Interview Questions (with Answers)
8. Explain useEffect with example.
useEffect is used for side effects like API calls, subscriptions.
Example:
useEffect(() => {
fetchData();
}, []);
9. What is useRef used for?
useRef returns a mutable ref object whose .current property is initialized to the passed argument. It can be
used to access DOM elements directly.
10. Difference between useMemo and useCallback?
useMemo returns a memoized value, useCallback returns a memoized function. Both are used to optimize
performance by preventing unnecessary re-renders.