Meteor: ReactMeteorData with Ecmascript6

- 1 answer

Ad

I am developing an application using Meteor and ReactJS. I am using the ES6 syntax for my React components. With the old syntax, you could do something like this:

MyComponent = React.createClass({
   mixins: [ReactMeteorData],

   render() {
    ...
   }
})

But how would this transfer over to ES6 syntax?

Help appreciated. Thank you!

Ad

Answer

Ad

When you refer to "ES6 syntax", do you mean creating React components with ES6 classes? Like the codes below:

class HelloMessage extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

Unfortuantely, there's no mixin support if you create React components with ES6 classes. You must use the React.createClass way.

The following is from React official documentation: Reusable Components:

No Mixins

Unfortunately, ES6 launched without any mixin support. Therefore, there is no support for mixins when you use React with ES6 classes. Instead, we're working on making it easier to support such use cases without resorting to mixins.

Ad
source: stackoverflow.com
Ad