Q. What is the primary role of React Router in React applications?

  • (A) To manage navigation and URL routing
  • (B) To handle HTTP requests
  • (C) To style components
  • (D) To manage component state
πŸ’¬ Discuss
βœ… Correct Answer: (A) To manage navigation and URL routing
Explanation: React Router allows for dynamic routing in single-page applications.

Q. How do you create a context in React?

  • (A) Using React.createContext()
  • (B) Using React.createComponent()
  • (C) Using React.useContext()
  • (D) Using React.Context()
πŸ’¬ Discuss
βœ… Correct Answer: (A) Using React.createContext()
Explanation: React.createContext creates a Context object.

Q. Which hook would you use to perform side effects such as data fetching in functional components?

  • (A) useEffect
  • (B) useState
  • (C) useMemo
  • (D) useRef
πŸ’¬ Discuss
βœ… Correct Answer: (A) useEffect
Explanation: useEffect runs side effects after render.

Q. What does React.Fragment help you do?

  • (A) Group multiple elements without adding extra nodes to the DOM
  • (B) Create new components
  • (C) Manage state across components
  • (D) Handle errors in components
πŸ’¬ Discuss
βœ… Correct Answer: (A) Group multiple elements without adding extra nodes to the DOM
Explanation: Fragments let you group elements without extra wrappers.

Q. Which attribute is used to specify inline styles in React?

  • (A) style (with an object)
  • (B) class
  • (C) className
  • (D) css
πŸ’¬ Discuss
βœ… Correct Answer: (A) style (with an object)
Explanation: The style attribute takes a JavaScript object with camelCase properties.

Q. What is reconciliation in React?

  • (A) The process React uses to update the DOM efficiently
  • (B) The process of combining components
  • (C) Merging CSS styles
  • (D) Handling user inputs
πŸ’¬ Discuss
βœ… Correct Answer: (A) The process React uses to update the DOM efficiently
Explanation: Reconciliation compares the new virtual DOM with the previous one.

Q. Which of these is a way to handle events in React?

  • (A) Using camelCase syntax like onClick
  • (B) Using lowercase like onclick
  • (C) Using jQuery event handlers
  • (D) Using HTML event attributes
πŸ’¬ Discuss
βœ… Correct Answer: (A) Using camelCase syntax like onClick
Explanation: React events use camelCase naming convention.

Q. In React, which statement about props is correct?

  • (A) Props are read-only and should not be modified by the component receiving them
  • (B) Props can be modified inside the child component
  • (C) Props are used to manage component state
  • (D) Props are only used in class components
πŸ’¬ Discuss
βœ… Correct Answer: (A) Props are read-only and should not be modified by the component receiving them
Explanation: Props are immutable from the perspective of the child component.

Q. Which hook can be used to access the previous value of a prop or state?

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

Q. What is the default value of useState when not provided?

  • (A) undefined
  • (B) null
  • (C) 0
  • (D) Empty string
πŸ’¬ Discuss
βœ… Correct Answer: (A) undefined
Explanation: If no initial state is passed, state is undefined initially.