Answer the question
In order to leave comments, you need to log in
How is the this.props property available in the class bean's render method?
While studying react, I ran into an illogical situation. In the method , the render
property is available, this.props
but in all other methods of the class, this property is not available.
It begs the question, where did it go?
If, according to the class logic, there is a property available in the method this
, it must have been initialized by someone, but I can’t get it even in the constructor.
It turns out that in fact there is none this.props
, and is it such syntactic sugar at the level balel
?
I made a mistake, this.props is available in the constructor.
console.log(this);
console.log(`props: ${JSON.stringify(this.props)}`);
{id: 1, name: 'haha', important: true}
constructor() {
super();
console.log(`props: ${JSON.stringify(this.props)}`);
console.log(``);
console.log(this);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question