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 />;
}
});
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+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With