user11661370
user11661370

Reputation:

When does the React component constructor run in relation to life cycle?

When does the React constructor run relative to component lifecycle?

The newest diagram I found for component lifecycle was here:

here

and it is from 2017 and does not include the constructor for some reason.

When does the constructor() run and is there a newer diagram available in mid 2019?

Upvotes: 0

Views: 75

Answers (2)

user11661370
user11661370

Reputation:

It will occur in the mount phase as seen in these two diagrams by Mosh

and by Hackernoon:

Upvotes: 0

Trevor-Indrek Lasn
Trevor-Indrek Lasn

Reputation: 316

The order the React components and constructor works are;

  1. The object memory is allocated
  2. The field variables with initial values are initialized
  3. Constructor is called
  4. React component code is called.

Upvotes: 1

Related Questions