Answer the question
In order to leave comments, you need to log in
With or without this?
Why do we do without this in the first example, but not in the second?
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Answer the question
In order to leave comments, you need to log in
Because in the first case you are accessing a function argument, and in the second case you are accessing a class field. All according to the canons of JavaScript .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question