I read in ES7 we can declare the state variables outside the constructor and also declare propTypes as a static properties, declared as high as possible within the component code.
import React, { Component } from 'react' import { string, object } from 'prop-types' export default class ProfileContainer extends Component { state = { expanded: false } static propTypes = { model: object.isRequired, title: string } static defaultProps = { model: { id: 0 }, title: 'Your Name' } }
Could anyone explain me what are the advantageous of doing it, Also I would want to know new features of ES7, A layman explanation.
Top comments (2)
You can add "React" to your title if that is your only interest.
I think you are confusing ES7 with ES10.
From what I know all browsers support features from
ES6 (2015) huge update, all the goodies
ES7 (2016) operator (**), Array.prototype.include
ES8 (2017) async/await
The ES9 2018 draft was finished in June 2018 so it will take some time for the browsers and frameworks to catch up.
I think your example contains features from different (old and future) versions of ES.
The class fields are just a proposal, so perhaps there will be implemented in ES10.
The "static" keyword exists since ES6 but only for methods.
thank you for your response, I thought class fields are introduced in ES7.