I’m trying to display the contents of a Collection, but I keep getting an empty list.
I’ve been using the Todos app as a template but I just can’t get it to retrieve data from the Collection. Here is what I have so far.
publications.js
import { Meteor } from 'meteor/meteor';
import Children from '../children.js';
Meteor.publish('children.public', function childrenPublic() {
return Children.find({
userId: { $exists: false },
}, {
fields: Children.publicFields,
});
});
children.js
import { Mongo } from 'meteor/mongo';
const Children = new Mongo.Collection('Children');
Children.publicFields = {
name: 0,
dateOfBirth: 0,
address: 0,
sponsor: 0,
situation: 0,
};
export default Children;
ChildrenPageContainer.jsx
import { Meteor } from 'meteor/meteor';
import { withTracker } from 'meteor/react-meteor-data';
import Children from '../../api/children/children.js';
import ChildrenPage from '../pages/Child/ChildrenPage.jsx';
const ChildrenPageContainer = withTracker(() => {
const publicHandle = Meteor.subscribe('children.public');
return {
user: Meteor.user(),
loading: !publicHandle.ready(),
connected: Meteor.status().connected,
children: Children.find({
$or: [
{ userId: { $exists: false } },
],
}).fetch(),
};
})(ChildrenPage);
export default ChildrenPageContainer;
And the ChildrenPage is basically MaterialUI Sorting and Selecting table: https://material-ui.com/components/tables/
The ChildrenPageContainer is supplied to the Route component like this:
<Route path="/child/list" component={ChildrenPageContainer} />
And I keep getting a warning in the browser console:
Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function`.
in Route (created by MainLayout)
in MainLayout
in ThemeProvider modules.js:3537:15
I have a feeling that the component does not rerender as the data arrive, and that this warning might have something to do with it. Either way, I am out of ideas, and would be very thankful if someone could point out the problem.