I know this question has been asked many times, but it is still unclear. Many simply said:
Pass the details for the constructor if you want to access this.propsthere
another example response
The official dock says Class components should always call the base constructor using props. but if we don’t pass propsin constructor, we will still have this.propseverywhere except the constructor.
Also from edit source code we can see the source code of React.Component
function ReactComponent(props, context) {
this.props = props;
this.context = context;
}
But it bothers me even more.
super()should be called with two parameters: propsand context. But we called our super empty and still have access to two this.props. According to the documentation, ECMA super()calls the parent constructor()with the parameters passed in super(). But ours is super()empty.
So my questions are:
- Why do official docs say:
Class components should always invoke the base constructor using props.
- How to React establishes
propssubsidiary component if super()and constructor()empty? - Is it a React function error that the attribute is available in the child component without passing the details
super()and constructor()?
source
share