ReactJS Interview Questions (Basic, Intermediate, Advanced)
1. Basic ReactJS Questions
- What is React, and why is it used?
Answer: React is a JavaScript library for building user interfaces. It allows component-based
architecture, improves performance using the Virtual DOM, and supports declarative UI.
- Difference between Props and State?
Answer: Props are read-only and passed from parent to child, while State is mutable and managed
within a component.
- What is JSX?
Answer: JSX (JavaScript XML) allows writing HTML-like syntax inside JavaScript.
- What are Fragments?
Answer: Fragments let you group multiple elements without adding extra DOM nodes.
- Why are keys important in lists?
Answer: Keys help React identify which items have changed, improving performance.
2. Intermediate ReactJS Questions
- What are Hooks? Why were they introduced?
Answer: Hooks allow using state and lifecycle methods in functional components. They were
introduced to avoid class components and make logic reusable.
- Difference between useMemo and useCallback?
Answer: useMemo caches the result of a computation, while useCallback caches the function itself.
- Explain Context API.
Answer: It allows global state sharing without prop drilling.
- How do you optimize React performance?
Answer: Memoization, code splitting with React.lazy, avoiding unnecessary re-renders, using
proper keys in lists.
3. Advanced ReactJS Questions
- What is Server-Side Rendering (SSR)?
Answer: Rendering React components on the server before sending HTML to the browser,
improving SEO and performance.
- Explain React Fiber.
Answer: Fiber is Reacts new reconciliation engine, enabling concurrent rendering and better
performance.
- What is Suspense in React?
Answer: Suspense allows components to wait for asynchronous data before rendering.
4. Coding Challenges
- Create a Counter using Hooks:
function Counter() {
const [count, setCount] = React.useState(0);
return (
<div>
<button onClick={() => setCount(count - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(count + 1)}>+</button>
</div>
);
- Build a To-Do App with Context API
- Implement a Debounced Search Input
- Create a Custom Hook for Fetching Data
5. Real-World Scenario Questions
- How would you design a React app for thousands of dynamic components without performance
issues?
- How would you persist user authentication state in a React app?
- How do you handle API errors and show fallback UIs?
- How would you migrate a large class-based React project to Hooks?
- How do you implement role-based access control in a React application?