DEV Community

madhu
madhu

Posted on

3 1

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️