React-redux decorators doesn't work with Meteor 1.4


#1

Hi guys, I’m running Meteor version 1.4.2 and react-redux version 4.4.5 on my project, and when I try to use the @connect decorator from the react-redux package nothing happens, it simply doesn’t run. Here’s my code:


import { Meteor } from 'meteor/meteor';

import React, { Component } from 'react';

import { connect } from 'react-redux';

import ArticleEditor from '../../pages/ArticleEditor.jsx';

@connect((store) => {
  console.log("@connect running");

  return { articles: store.articles }
})
export default class ArticleEditorContainer extends Component {
  componentWillMount() {
    this.sub =  Meteor.subscribe('articles');
  }

  componentWillUnmount() {
    this.sub.stop();
  }

  render() {
    return <ArticleEditor {...this.props} />;
  }
}

And when I check with the ReactDevTools there’s no sign of the @connect wrapper. However, it does work when I use it like that:

import { connect } from 'react-redux';

class ArticleEditorContainer extends Component {
  componentWillMount() {
    this.sub =  Meteor.subscribe('articles');
  }

  componentWillUnmount() {
    this.sub.stop();
  }

  render() {
    return <ArticleEditor {...this.props} />;
  }
}

export default connect((store) => { /* ... */ })(ArticleEditorContainer);

Is there a way to make the decorator work? Or ES7 decorators aren’t supported at all?


#2

I think you need this babel plugin to make them work.

I do not use decorators myself, so I can’t say for sure.


#3

I suppose Meteor uses babel, is it possible to configure it using .babelrc file?


#4

Yes, you can configure it with .babelrc.


#5

It does work, thanks!