When does the constructor method get called?

Question

In the context of this exercise, when does the constructor method get called?

Answer

The constructor method is invoked when a new component instance is created and runs before the entire component’s lifecycle starts. It runs before componentWillMount, which is the start of the mounting phase of the component.

10 Likes

I haven’t seen creating instances of the component classes in the codecademy exercies, its always been render the class component, then when are they being called ? Please explain.

its explained here:

https://reactjs.org/docs/react-component.html#mounting

which contains the following explanation: These methods are called in the following order when an instance of a component is being created and inserted into the DOM:

i wouldn’t call it a problem, but react does a lot of stuff under the hood (under water if you like), including creating the class instance.

if you want to learn more about classes and creating class instances, i would do this in pure JS to improve your understanding of classes, so you can better “see” how react might do this.