React Questions
1. What are the key features of React.js?
React is a JavaScript library for building fast, reusable UI components.
It uses virtual DOM, unidirectional data flow, and supports hooks.
2. What is the difference between React and Angular?
React is a library focused on UI; Angular is a full-fledged framework.
React uses virtual DOM; Angular uses real DOM and two-way binding.
3. What is JSX and why is it used?
JSX lets you write HTML in JavaScript.
It makes code readable and helps create UI components easily.
4. What are components in React? Difference between functional and class
components?
Components are reusable UI blocks.
Functional components use hooks; class components use lifecycle methods.
5. What are props and state in React?
Props are inputs to components (read-only).
State is internal data that can change over time.
6. What is the virtual DOM and how does React use it?
Virtual DOM is a lightweight copy of real DOM.
React updates it first and then updates only the changed parts in real DOM.
7. What are React Hooks? Explain useState, useEffect, and useRef.
Hooks let you use state and lifecycle in functional components.
useState manages state, useEffect handles side effects, useRef holds mutable values.
8. What is the difference between useEffect and componentDidMount?
componentDidMount runs once after mounting (class).
useEffect(() => {}, []) is its equivalent in functional components.
9. What are controlled and uncontrolled components in React?
Controlled components use React state to manage form data.
Uncontrolled components use DOM refs to access values.
10. What is the purpose of keys in React lists?
Keys help React identify which items changed, added, or removed.
They improve rendering performance in lists.
11. What is prop drilling and how can it be avoided?
Prop drilling is passing props through many layers.
Use Context API or Redux to avoid it.
12. What is context API in React and how is it used?
Context API shares global data without passing props manually.
Use createContext, Provider, and useContext to access data.
13. What is Redux? How does it work with React?
Redux is a state management library for JavaScript apps.
React components use useSelector, useDispatch to access/store/update global state.
14. What are middleware in Redux? Explain redux-thunk and redux-saga.
Middleware sits between actions and reducers for async logic.
redux-thunk allows async functions, redux-saga uses generators.
15. What is the difference between Redux and Context API?
Context is for small-scale state sharing.
Redux is better for large apps with complex state and middleware.
16. What is React Router and how does routing work in React?
React Router handles navigation in single-page apps.
It maps URLs to components using <Route> and <Link>.
17. What is lazy loading and code splitting in React?
Lazy loading loads components only when needed.
Code splitting breaks code into smaller bundles to improve load time.
18. What is the difference between SSR, CSR, and SSG?
CSR: Client renders page (React default).
SSR: Server renders HTML. SSG: Pre-builds pages at build time.
19. What are higher-order components (HOCs) in React?
HOCs are functions that take a component and return a new one.
Used for reusing logic across components.
20. What is memoization in React? Explain React.memo and useMemo.
Memoization caches results to avoid re-renders.
React.memo wraps components, useMemo caches values.
21. How does React handle forms and validation?
React handles form data with state.
Validation is done manually or using libraries like Formik or Yup.
22. What is the significance of lifting state up in React?
When two components need to share state, lift it to their parent.
This helps keep state centralized and consistent.
23. What are portals in React?
Portals let you render components outside the parent DOM tree.
Useful for modals and tooltips.
24. How does error boundary work in React?
Error boundaries catch runtime errors in child components.
They show fallback UI instead of crashing the app.
25. What are some performance optimization techniques in React?
Use React.memo, useMemo, lazy loading, and key props properly.
Avoid unnecessary re-renders and large states.
26. What are the new features introduced in recent React versions (like Suspense,
Concurrent Mode)?
Suspense allows lazy loading with a fallback UI.
Concurrent Mode improves rendering by making it interruptible and smooth.