如何在 Meteor 1.3 应用程序中结合 react-redux 和 react-meteor-data?

How to combine react-redux and react-meteor-data in a Meteor 1.3 application?

如何使用 react-redux 中的 state 属性来指定由 react-meteor-data 注入的数据?

react组件的结构如下:

  import React from "react";
  import {createContainer} from "meteor/react-meteor-data";
  import {connet} from "react-redux";
  import {Data} from "./data.js"

  class App extends React.Component {
     render() {
        return (
           <div>
              {JSON.stringify(this.props.profile)}
           </div>
        );
     }   
  }
  const mapStateToProps = state => ({
      ID: state.dataId    // ID gets assigned to props here
  });

  export default createContainer(
      () => ({
         profile: Data.findOne({_id: >>>ID<<<})   // ID is needed here
      }), 
      connect(mapStateToProps)(App)
  );

非常感谢!

你应该看看 React-Komposer,它具有 redux 和流星跟踪器的功能。

https://github.com/kadirahq/react-komposer

使用 komposer 你会得到两个参数 propsonData

props 是传递给容器的道具,onData 是要发送到组合组件的新道具。

现在,为了将两个系统连接在一起,我不确定这是否可行或者是否是最佳解决方案,但我认为您可以这样做

connect(mapStateToProps)(composeWithTacker(onPropsChange)(App))