Hello,
Can someone look at below and let me know what I am doing wrong. Its driving me nuts…
/* imports/api/globaladmin/users.js */
export const Users = Meteor.users; //Pretty sure this is the problem!!
and…
/* imports/api/globaladmin/server/publications.js */
import { Users } from '../users';
Meteor.publish('users-list', () => Users.find());
The above is where I think the error is, but not sure what to do… How do you publish and subscribe Meteor.users properly in react?
My components, users-list and user are below…
/* imports/ui/components/globaladmin/users-list.js */
import React, { Component, PropTypes } from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { Users } from '../../../api/globaladmin/users.js';
import User from './user.js';
class UsersList extends Component {
getUsers() {
// console.log('this.props.users:', this.props.users);
return this.props.users.map((user) => {
console.log('user:', user);
return (
<User
key = {user._id}
user = {user}
/>
);
});
}
render() {
console.log('this.props.users:', this.props.users);
return (
<div className="container">
{this.getUsers()}
</div>
);
}
}
UsersList.propTypes = {
users: PropTypes.array.isRequired,
};
export default createContainer(() => {
Meteor.subscribe('users-list');
return {
users: Users.find({}).fetch(),
};
}, UsersList);
/* imports/ui/components/globaladmin/user.js */
import React from 'react';
export default class User extends React.Component {
render() {
return (
<li>{this.props.user._id}</li>
);
}
}
User.propTypes = {
user: React.PropTypes.object.isRequired,
};
Just moving to React, so making some noob mistake. The output is only the userid of the user i am logged in as, when what i am looking for is all the users. Clearly I am not subscribing properly, but not sure how to fix.
If I remove the publish and subscribe, it still works fine, which means I am not accessing the thing properly. I have turned off insecure and autopublish.
Thanks so much.
Tat