These methods are called in the following order when an instance of a component is created and inserted into the DOM:
- constructor()
- render()
- componentDidMount() ⬅
componentDidMount()
is called immediately after componentrender()
, after the component is mounted (inserted into the DOM).- Since the
render()
method is already executed, DOM will be already present. Which means that we can reference DOM and our component insidecomponentDidMount()
. - We should be aware that calling
setState()
here will lead to the re-rendering of the component (can affect performance).