Accepted answer

from the docs,

does useeffect run after every render? yes! by default, it runs both after the first render and after every update. (we will later talk about how to customize this.) instead of thinking in terms of “mounting” and “updating”, you might find it easier to think that effects happen “after render”. react guarantees the dom has been updated by the time it runs the effects.

you can provide the empty dependency array / [] as second argument to useeffect, it is same as componentdidmount which will executes only once in component life cycle.

useeffect(() => {
}, []); //this will run only once 


pass empty [] as an second argument to useeffect method. it will be called on initial render, like below.

  useeffect(() => {
  }, []); 

Related Query

More Query from same tag