arunoda / react-komposer

Feed data into React components by composing containers.
MIT License
732 stars 70 forks source link

How to subscribe with meteor ? #137

Closed lyquocnam closed 7 years ago

lyquocnam commented 7 years ago

Hi author, i tried with this code, but handle.ready() not work, please help !

import HomeComponent from '../components/HomeComponent';
import { compose } from 'react-komposer';
import { Meteor } from 'meteor/meteor';
import Products from '/lib/collections';

function composer(props, onData) {

    const handle =  Meteor.subscribe('products.list');

    if (handle.ready()) {
        const items = Products.find({}).fetch();
        return onData(null, {
            // truyen du lieu cho component.
            items: items,
        });
    }
    else {
        return onData();
    }

}

export default compose(composer)(HomeComponent);

in server file:

Meteor.publish('products.list', function () {
  return Products.find({});
});
arunoda commented 7 years ago

You need to use getTrackerLoader as instructed here: https://github.com/arunoda/react-komposer#for-meteors-tracker