Q. What happens if you update state directly in React?

  • (A) React throws an error
  • (B) It updates the component correctly
  • (C) The component won’t re-render
  • (D) It updates all components
πŸ’¬ Discuss
βœ… Correct Answer: (C) The component won’t re-render
Explanation: React won't detect changes if state is mutated directly instead of using setState.

Q. Which hook is used to manage state in functional components?

  • (A) useEffect
  • (B) useContext
  • (C) useReducer
  • (D) useState
πŸ’¬ Discuss
βœ… Correct Answer: (D) useState
Explanation: `useState` is the primary hook used for state management in functional components.

Q. What does the second value returned by useState represent?

  • (A) The previous state
  • (B) The default value
  • (C) A function to update the state
  • (D) A backup value
πŸ’¬ Discuss
βœ… Correct Answer: (C) A function to update the state
Explanation: `useState` returns an array with the current state and a function to update it.

Q. What is the primary purpose of React Router?

  • (A) To handle HTTP requests
  • (B) To manage component lifecycle
  • (C) To enable routing in single-page applications
  • (D) To connect components with Redux
πŸ’¬ Discuss
βœ… Correct Answer: (C) To enable routing in single-page applications
Explanation: React Router allows dynamic routing in SPAs based on the URL.

Q. Which component in React Router is used to define a route?

  • (A) Router
  • (B) Route
  • (C) Link
  • (D) Switch
πŸ’¬ Discuss
βœ… Correct Answer: (B) Route
Explanation: `Route` defines the path and component to render for a given URL.

Q. What is React's virtual DOM?

  • (A) A copy of the real DOM that updates instantly
  • (B) An abstraction for server rendering
  • (C) A browser extension
  • (D) A CSS rendering engine
πŸ’¬ Discuss
βœ… Correct Answer: (A) A copy of the real DOM that updates instantly
Explanation: Virtual DOM is an in-memory representation of the real DOM used for efficient diffing.

Q. What is the role of the `key` prop in lists?

  • (A) To sort elements
  • (B) To style elements
  • (C) To uniquely identify elements
  • (D) To define props
πŸ’¬ Discuss
βœ… Correct Answer: (C) To uniquely identify elements
Explanation: Keys help React identify which items have changed or been removed.

Q. What is `useReducer` typically used for?

  • (A) For animation
  • (B) For complex state logic
  • (C) For routing
  • (D) For lazy loading
πŸ’¬ Discuss
βœ… Correct Answer: (B) For complex state logic
Explanation: `useReducer` is helpful for managing complex state transitions.

Q. Which React method is used to clean up resources in a component?

  • (A) componentCleanup
  • (B) useEffect return function
  • (C) useMemo
  • (D) componentDispose
πŸ’¬ Discuss
βœ… Correct Answer: (B) useEffect return function
Explanation: Returning a function from `useEffect` handles clean-up logic like unsubscribing or clearing timers.

Q. Which of the following hooks is used to persist values across renders without causing re-renders?

  • (A) useState
  • (B) useEffect
  • (C) useMemo
  • (D) useRef
πŸ’¬ Discuss
βœ… Correct Answer: (D) useRef
Explanation: `useRef` persists values without triggering re-renders.