Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I use state properties from react-redux to specify the data that is injected by react-meteor-data?

The structure of the react component is as follows:

  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)
  );

Many thanks!

like image 910
thando Avatar asked Sep 20 '25 00:09

thando


1 Answers

You should take a look at React-Komposer, it has functionality for redux as well as meteor trackers.

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

with komposer you will get two params props and onData

props are the props passed to your container and onData is the new props to be sent to the composed component.

Now for connecting both of the systems together, I'm not positive this will work or is the best solution but I'm thinking you could do something like this

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

like image 64
Patrick Mencias-lewis Avatar answered Sep 22 '25 15:09

Patrick Mencias-lewis