I recently started to learn ReactJS and therefore ES6. I am very familiar with ES5, but some things are not so clear to me.
Example 1: Method Syntax
What is the difference between the following two methods?
export class InvoiceForm extends React.Component {
methodName1() {
}
methodName2 = () => {
};
}
Example 2: class properties outside
class Greeting extends React.Component {
render() {
return (
<h1>Hello, {this.props.name}</h1>
);
}
}
Greeting.propTypes = {
name: PropTypes.string
};
propTypesis out of class. But why? I came from python, and as for me, it’s more correct
class Greeting extends React.Component {
static propTypes = {
name: PropTypes.string
}
render() {
return (
<h1>Hello, {this.props.name}</h1>
);
}
}
source
share