Hello,
I need to check if user has requested free demo in react. So in my server/main.js i have included
Meteor.publish(‘freeDemos’,function(){
return FreeDemo.find({
ownerId:this.userId
});
})
At the start, hasDemo will be empty because the subscription is being initialized. After the initialization, the component is already mounted so placing it in the constructor means that props.hasDemo will be undefined.
Use getDerivedStateFromProps() instead or componentDidUpdate() depending on what you wanted to do. Check React’s documentation of getDerivedStateFromProps() for proper use.
Are you getting any errors in browser console or on the server? Does the console.log in the hasDemo publish run? (you are missing a .fetch() there to actually get anything
I20180830-19:38:09.785(5.5)? Exception from sub hasDemo id ghWJ3n32w4jtXLxQW Error: Publish function can only return a Cursor or an array of Cursors
I20180830-19:38:09.786(5.5)? at Subscription._publishHandlerResult (packages/ddp-server/livedata_server.js:1129:18)
I20180830-19:38:09.786(5.5)? at Subscription._runHandler (packages/ddp-server/livedata_server.js:1060:10)
I20180830-19:38:09.787(5.5)? at Session._startSubscription (packages/ddp-server/livedata_server.js:859:9)
I20180830-19:38:09.787(5.5)? at Session.sub (packages/ddp-server/livedata_server.js:625:12)
I20180830-19:38:09.788(5.5)? at packages/ddp-server/livedata_server.js:559:43
Any Idea? I did search in google but they occur for different reason. What I am doing normal publish way?