Q. What does lifting state up mean in React?

  • (A) Creating global state
  • (B) Passing state to Redux
  • (C) Moving state to a common ancestor component
  • (D) Using local storage
πŸ’¬ Discuss
βœ… Correct Answer: (C) Moving state to a common ancestor component
Explanation: Lifting state up means moving state to the nearest common ancestor to share it across components.

Q. What is a pure component?

  • (A) A component that uses only functional logic
  • (B) A component that does not re-render unnecessarily
  • (C) A component without any state
  • (D) A component with only props
πŸ’¬ Discuss
βœ… Correct Answer: (B) A component that does not re-render unnecessarily
Explanation: Pure components implement shouldComponentUpdate with shallow prop and state comparison.

Q. How many root elements can a React component return?

  • (A) Multiple
  • (B) Only one
  • (C) Zero
  • (D) As many as you want
πŸ’¬ Discuss
βœ… Correct Answer: (B) Only one
Explanation: React components must return a single root element, which can be a div or React.Fragment.

Q. Which hook replaces lifecycle methods in functional components?

  • (A) useEffect
  • (B) useCallback
  • (C) useMemo
  • (D) useReducer
πŸ’¬ Discuss
βœ… Correct Answer: (A) useEffect
Explanation: useEffect allows performing side effects and replaces componentDidMount, componentDidUpdate, and componentWillUnmount.

Q. What happens if you use the same key for elements in a list?

  • (A) React warns but works fine
  • (B) Only the first element renders
  • (C) Unexpected behavior may occur
  • (D) Nothing happens
πŸ’¬ Discuss
βœ… Correct Answer: (C) Unexpected behavior may occur
Explanation: Using non-unique keys can cause rendering issues in lists.

Q. Which hook helps you prevent unnecessary function recreation?

  • (A) useRef
  • (B) useCallback
  • (C) useReducer
  • (D) useMemo
πŸ’¬ Discuss
βœ… Correct Answer: (B) useCallback
Explanation: useCallback memoizes a function so it's not recreated on every render.

Q. What is the main benefit of using React?

  • (A) Server-side rendering
  • (B) Fast and efficient UI updates
  • (C) Security
  • (D) Database support
πŸ’¬ Discuss
βœ… Correct Answer: (B) Fast and efficient UI updates
Explanation: React’s virtual DOM makes UI updates efficient.

Q. What is the role of a key in a list of elements?

  • (A) To apply styles
  • (B) To identify which items changed
  • (C) To improve performance
  • (D) To bind events
πŸ’¬ Discuss
βœ… Correct Answer: (B) To identify which items changed
Explanation: Keys help React identify which items have changed, are added, or removed.

Q. What happens when setState is called?

  • (A) The component is replaced
  • (B) The component is re-rendered
  • (C) Nothing happens
  • (D) The whole DOM is rebuilt
πŸ’¬ Discuss
βœ… Correct Answer: (B) The component is re-rendered
Explanation: Calling setState triggers a re-render with the updated state.

Q. How do you handle forms in React?

  • (A) Using traditional HTML methods
  • (B) Using refs only
  • (C) Using controlled components
  • (D) Only with third-party libraries
πŸ’¬ Discuss
βœ… Correct Answer: (C) Using controlled components
Explanation: In React, form elements are often controlled using state.