M

Mr. Dubey • 100.28K Points
Coach

Q. How do you ensure a component only mounts once with a side-effect?

  • (A) Use useEffect without dependencies
  • (B) Use useEffect with an empty array
  • (C) Use componentDidUpdate
  • (D) Use useState
  • Correct Answer - Option(B)
  • Views: 21
  • Filed under category React Js

Explanation by: Mr. Dubey
Using `useEffect(() => {}, [])` ensures the side-effect runs only once.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.


Question analytics