javascript - Get data from a reactive container -


from docs, need use reactive data container around component retrieve logged in user (if 1 exists), how data container?

import { meteor } 'meteor/meteor'; import react, { component } 'react'; import { createcontainer } 'meteor/react-meteor-data';  export default foocontainer = createcontainer(() => {   return {     user: meteor.user()   }; }, class foocomponent extends component {    render() {     return (<div>{ /* this.data.user ??? */ }</div>);   } }); 

how data returned container function inside render method?

i see returned user key in container, therefore data accessible via this.props.user prop in component.

just make sure add container:

export default foocontainer = createcontainer(() => { const subscription = meteor.subscribe("userdata"); subscription.ready() ? session.set("dataready", true) : session.set("dataready", false);    return {     user: meteor.user()   }; } 

and in render method:

 render() {     if(session.get("dataready")){ return (<div>{ /* this.data.user ??? */ }</div>); }   } 

trust me, save lot of headache , lot of errors in future. make sure data 100% ready before it's called , rendered in component.

oh, assuming have autopublish removed, publish particular user's data in order subscribe showed above:

meteor.publish("userdata", function(){   return meteor.users.find({_id: this.userid}); }); 

just heads up.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -