2

When will you hit the componentDidMount hook in react? is it when the component is mounted to the virtual dom or actual dom?

Charitha Goonewardena
  • 4,418
  • 2
  • 36
  • 38

1 Answers1

3

The component is mounted to the Virtual DOM on render(), at the "Render phase".

The componentDidMount lifecycle, which is part of the "Commit phase", is mounted to the actual DOM.

Notice that you can have another render phase if you call setState in the componentDidMount.

You may call setState() immediately in componentDidMount(). It will trigger an extra rendering, but it will happen before the browser updates the screen.

Dennis Vash
  • 50,196
  • 9
  • 100
  • 118