Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

childContextTypes in ES6

How would you write the object childContextTypes in ES6?

var A = React.createClass({

    childContextTypes: {
         name: React.PropTypes.string.isRequired
    },

    getChildContext: function() {
         return { name: "Jonas" };
    },

    render: function() {
         return <B />;
    }
});
like image 272
Chris G. Avatar asked Aug 18 '15 17:08

Chris G.


1 Answers

Since you are using Babel anyway, you can use static (ES7) in your code like this:

export default class A extends React.Component {

  static childContextTypes = {
    name: React.PropTypes.string,
  }

  getChildContext() {
    return { name: "Jonas" }
  }

  render() {
    return <B />
  }
}

More info: React on ES6+

like image 153
cutemachine Avatar answered Sep 30 '22 08:09

cutemachine