I do renderContacts and I'm trying to get results in a div with a contactResults id by calling renderContacts. It looks like that the problem is that the renderContacts() function doesn't wait for a Meteor.call and returns undefined right away. However, in the Meteor.call callback I get the right data from backend. So the problem only is that I don't know how I can make it to wait to a Meteor.call's callback.
class ContactsComponent extends React.Component {
renderContacts() {
return Meteor.call('parseClients', function(err, updatedContacts) {
if (err) {
console.log(err);
} else {
console.log(updatedContacts); // correct result in here
if (updatedContacts.length) {
return contacts.map((contact, i) => (
<SingleContactRow key={contact._id} contact={contact}/>
));
}
}
});
}
render() {
return (
<div>
<div>
<div id="contactResults">
{this.renderContacts()}
</div>
</div>
</div>
);
}
}
Here is the backend function:
'parseClients'() {
return Contacts.findOne({});
}