What is super (props) for my React component?

I do not really like JS and play with React.

The React docs located here report the following:

When implementing a constructor for a subclass, React.Componentyou must call super(props)before any other statement. Otherwise, it this.propswill be undefined in the constructor, which can lead to errors.

My question is: HOW does this really work? What is super()what magically includes this.propsinside my constructor?

+4
source share
1 answer

In the documentation you mentioned. It is encoded in ES6 javascript standard.

So this statement

class Greeting extends React.Component

, Greeting React.Component, super, props,

this.props constructor, super(props)

Hope .

+7

Source: https://habr.com/ru/post/1667685/


All Articles