πŸ“Š React Js
Q. Which lifecycle method is invoked immediately after a component is mounted?
  • (A) componentWillMount
  • (B) componentDidMount
  • (C) componentDidUpdate
  • (D) componentWillUpdate
πŸ’¬ Discuss
βœ… Correct Answer: (B) componentDidMount

Explanation: componentDidMount is called immediately after the component is mounted.

πŸ“Š React Js
Q. Which hook is used to store a mutable value that does not cause re-render?
  • (A) useMemo
  • (B) useRef
  • (C) useState
  • (D) useEffect
πŸ’¬ Discuss
βœ… Correct Answer: (B) useRef

Explanation: useRef stores a mutable value that persists across renders without triggering re-render.

πŸ“Š React Js
Q. Which company developed React?
  • (A) Google
  • (B) Facebook
  • (C) Twitter
  • (D) Microsoft
πŸ’¬ Discuss
βœ… Correct Answer: (B) Facebook

Explanation: React was developed and is maintained by Facebook.

πŸ“Š React Js
Q. What is the correct syntax to handle an event in React?
  • (A) onclick={handleClick}
  • (B) onClick=handleClick()
  • (C) onClick={handleClick}
  • (D) onclick=handleClick()
πŸ’¬ Discuss
βœ… Correct Answer: (C) onClick={handleClick}

Explanation: React uses camelCase for event handlers and passes functions inside curly braces.

πŸ“Š React Js
Q. What does the useEffect hook return?
  • (A) Nothing
  • (B) A function for rendering
  • (C) A cleanup function
  • (D) A state value
πŸ’¬ Discuss
βœ… Correct Answer: (C) A cleanup function

Explanation: useEffect can return a cleanup function that runs when the component unmounts or before the effect re-runs.

πŸ“Š React Js
Q. What is the second argument of useEffect used for?
  • (A) To provide initial value
  • (B) To define dependencies
  • (C) To define return type
  • (D) To prevent rendering
πŸ’¬ Discuss
βœ… Correct Answer: (B) To define dependencies

Explanation: The second argument is an array of dependencies; the effect re-runs when any dependency changes.

πŸ“Š React Js
Q. Which of the following is true about React keys?
  • (A) They should be random
  • (B) They should be strings only
  • (C) They must be unique among siblings
  • (D) They must be global
πŸ’¬ Discuss
βœ… Correct Answer: (C) They must be unique among siblings

Explanation: Keys help React identify elements; they must be unique within their list context.

πŸ“Š React Js
Q. What will happen if you change the state directly without setState or useState?
  • (A) The component will update
  • (B) The component will not re-render
  • (C) An error will occur
  • (D) React will auto-detect changes
πŸ’¬ Discuss
βœ… Correct Answer: (B) The component will not re-render

Explanation: React will not re-render if state is mutated directly without using setState or the setter function from useState.

πŸ“Š React Js
Q. How can props be made optional in a functional component?
  • (A) By setting default values
  • (B) By using useEffect
  • (C) By passing null
  • (D) By skipping render
πŸ’¬ Discuss
βœ… Correct Answer: (A) By setting default values

Explanation: Props can be made optional by setting default values directly or using defaultProps.

πŸ“Š React Js
Q. What does the 'key' prop help React identify?
  • (A) The source of the event
  • (B) The value of a form
  • (C) Which items have changed
  • (D) The root element
πŸ’¬ Discuss
βœ… Correct Answer: (C) Which items have changed

Explanation: React uses 'key' to identify which items in the list are changed, added, or removed.