Q. Which of these hooks can replace both useState and useReducer in certain scenarios?

  • (A) useReducer
  • (B) useState
  • (C) useEffect
  • (D) useRef
πŸ’¬ Discuss
βœ… Correct Answer: (A) useReducer
Explanation: useReducer can manage state and complex state transitions.

Q. What will happen if a React component returns false in its render method?

  • (A) It will render nothing
  • (B) It will throw an error
  • (C) It will render 'false' text
  • (D) It will crash the app
πŸ’¬ Discuss
βœ… Correct Answer: (A) It will render nothing
Explanation: Returning false or null means nothing is rendered.

Q. What does 'lifting state up' help to solve in React?

  • (A) Sharing state between sibling components
  • (B) Passing props to child components
  • (C) Styling components
  • (D) Handling events
πŸ’¬ Discuss
βœ… Correct Answer: (A) Sharing state between sibling components
Explanation: State is moved to the closest common ancestor to share it.

Q. What is the React DevTools used for?

  • (A) Inspecting React component hierarchy and state/props
  • (B) Building React components
  • (C) Managing backend APIs
  • (D) Styling React components
πŸ’¬ Discuss
βœ… Correct Answer: (A) Inspecting React component hierarchy and state/props
Explanation: React DevTools helps debug React apps.

Q. Which of the following is NOT true about React hooks?

  • (A) Hooks can only be called at the top level of a component
  • (B) Hooks can be called inside loops and conditions
  • (C) Hooks let you use state and other React features without classes
  • (D) Hooks follow the Rules of Hooks
πŸ’¬ Discuss
βœ… Correct Answer: (B) Hooks can be called inside loops and conditions
Explanation: Hooks must be called unconditionally at the top level.

Q. What is the main benefit of using useMemo hook?

  • (A) To memoize expensive calculations and avoid re-computations
  • (B) To manage side effects
  • (C) To access the DOM directly
  • (D) To fetch data asynchronously
πŸ’¬ Discuss
βœ… Correct Answer: (A) To memoize expensive calculations and avoid re-computations
Explanation: useMemo caches computed values between renders.

Q. What is the purpose of the React.StrictMode component?

  • (A) To highlight potential problems in an application during development
  • (B) To enable production optimizations
  • (C) To enforce CSS styling
  • (D) To disable lifecycle methods
πŸ’¬ Discuss
βœ… Correct Answer: (A) To highlight potential problems in an application during development
Explanation: StrictMode helps detect unsafe lifecycle methods, legacy API usage, and more.

Q. How do you pass data from a child component to a parent component in React?

  • (A) By passing a callback function from the parent to the child and invoking it with data
  • (B) By using props directly from the child
  • (C) By using the Context API only
  • (D) By modifying the parent's state directly
πŸ’¬ Discuss
βœ… Correct Answer: (A) By passing a callback function from the parent to the child and invoking it with data
Explanation: Data flows down via props; child can send data up via callbacks.

Q. What is the purpose of the useRef hook?

  • (A) To access and persist mutable values without causing re-renders
  • (B) To manage component state
  • (C) To trigger side effects
  • (D) To memoize functions
πŸ’¬ Discuss
βœ… Correct Answer: (A) To access and persist mutable values without causing re-renders
Explanation: useRef returns a mutable ref object that persists across renders.

Q. Which method in React class components can be used to update the state?

  • (A) this.setState()
  • (B) this.updateState()
  • (C) this.modifyState()
  • (D) this.changeState()
πŸ’¬ Discuss
βœ… Correct Answer: (A) this.setState()
Explanation: setState() schedules an update to a component's state.