DEV Community

madhu
madhu

Posted on

What are the advantages of ES7 over ES6 (Focusing on React)?

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'
  }

}
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
bgadrian profile image
Adrian B.G. • Edited

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.

Collapse
 
madhu profile image
madhu

thank you for your response, I thought class fields are introduced in ES7.