Open simsim0709 opened 7 years ago
You don't need to change here for SSR. But inside your reactiveMapper code.
Like this:
function reactiveMapper(props, onData) {
if (Meteor.isServer) {
const post = return Posts.findOne({_id: props.id});
return onData(null, { post })
}
const handle = Meteor.subscribe('post', props.id);
if (handle.ready()) {
const post = return Posts.findOne({_id: props.id});
return onData(null, { post })
}
// Indicate a loading screen otherwise
return onData();
}
I didn't try this. But it should be something like this.
@arunoda this code const post = return Posts.findOne({_id: props.id})
is invalid, can you please explain
@simsim0709 any luck with SSR ?
my code is:
function reactiveMapper(props, onData, {Meteor, FlowRouter, collections}) {
const list = collections.Estates.find({}).fetch();
console.log('list', Meteor.isServer, list.length)
onData(null, {
loading: !Meteor.subscribe('estates.search', routerParamsToObject(FlowRouter)).ready(),
list
});
}
log on server: list true 0
log on client: list false 44
its working, when i put subscription before find
call
function reactiveMapper(props, onData, {Meteor, FlowRouter, collections}) {
const loading = !Meteor.subscribe('estates.search', routerParamsToObject(FlowRouter)).ready() // subscribe first
const list = collections.Estates.find({}).fetch() // than fetch
console.log('list', Meteor.isServer, list.length)
onData(null, {
loading,
list
});
}
I have a question regarding SSR section
I am using Meteor, React with React Router, and I have implemented
getTrackerLoader
code from the documentation.Do I need to take care of SSR on getTrackerLoader?? Something like this.