reactjs - Meteor Publish/Subscribe with users data -
i'm banging head against brick wall this. cannot seem find example works me.
this server side
meteor.publish("alluserdata", function () { return meteor.users.find({}, {fields: {'username': 1, 'profile': 1}}); }, {is_auto: true});
and client
var alluserdata = meteor.subscribe("alluserdata"); tracker.autorun(function() { if (alluserdata.ready()) { console.log('ready'); } });
i 'ready' logging cannot see how iterate through returned data???
for react, can set props on component createcontainer(). e.g.
import react, {component} 'react'; import {createcontainer} 'meteor/react-meteor-data'; class foocomponent extends component { constructor(props) { super(props); } render() { if (this.props.loading) { return ( <div>loading</div> ) } return ( { this.props.users.map(function(user, index) { return ( <div key={index.tostring()}> {user.username} </div> ) }, this) } ) } } export default createcontainer(() => { let handle = meteor.subscribe('alluserdata'); let users = meteor.users.find({}); let loading = !handle.ready(); return { users, loading } }, foocomponent);
i haven't tested this, if it's not right think it's @ least kinda close. forgive me if i've gotten wrong, react skills still pretty newish.
Comments
Post a Comment