MChan
MChan

Reputation: 7202

Meteor 1.4 - React data loading techniques best practice

I am using Meteor 1.4 / React to build a medium sized app. so I am trying to find the 'best practice' for data handling between Meteor 1.4 / React to follow when building my app.

At the moment I am using createContainer to handle data between Meteor and React components as shown in the example below.

Having said that, I've read in many articles / forum posts about using Meteor packages / features like React Komposer, TrackerReact, and React Document container.

So I am not sure which of them is best to follow for a medium sized project that will by time increase in size. So I was wondering if someone passed with similar experience / tried those packages can share with me their experience?

Thanks in advance for your help and time

  import React, { Component } from 'react';
  import { createContainer } from 'meteor/react-meteor-data';

  export default class DDOrganization extends Component {

      getOrganizations(){
        let org = this.props.org;
        return Organizations.find({'name': {'$regex': org}});
      }

      renderOrganizations(){
        return this.getOrganizations().bind(this).map((org) => {
          return (
            <li key={org._id}><a href="#" data-id={org._id} onClick={this.props.setOrgState}>{org.name}</a></li>
          )
        });
      }

      render(){
          let {organizations} = this.props;
          return (
              <ul className="select-organization-list">
                  {this.renderOrganizations().bind(this)}
              </ul>
          )
      }

  };


  export default createContainer(() => {

      let organizations = {};
      let {org} = this.props;
      let orgSub = Meteor.subscribe("OrgSubscription", org);

      if(orgSub.ready()){
          organizations = Organizations.find({'name': {'$regex': org}}).fetch();
      }

      return {
          organizations: organizations
      }

  }, DDOrganization);

Upvotes: 1

Views: 322

Answers (1)

Robert Fines
Robert Fines

Reputation: 720

I am doing things the same way that you are currently doing them for a pretty large project in production and it seems to work pretty well. I believe it is the recommended method by MDG.

Upvotes: 2

Related Questions