Recently I've started to learn ReactJS and consequently - ES6. I'm quite familiar with ES5, but some things are not that clear for me.
Example 1: Methods 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
};
propTypes
is outside the class. But why? I came from python
and as for me, the following is more correct
class Greeting extends React.Component {
static propTypes = {
name: PropTypes.string
}
render() {
return (
<h1>Hello, {this.props.name}</h1>
);
}
}