2016-12-02 70 views
0

我現在有我的反應,komposer設置是這樣的:是否可以通過React Komposer傳遞道具?

const composer = (params, onData) => { 
 
    const subscription = Meteor.subscribe('comments'); 
 
    if (subscription.ready()) { 
 
    const comments = Comments.find({approved: true }, {sort: {timestamp: -1}}).fetch(); 
 
    onData(null, { comments }); 
 
    } 
 
}; 
 

 
export default composeWithTracker(composer, Loading)(CommentsList);

我想什麼是另一種選擇傳遞給它基於該組件的道具我查找查詢。

所以我想它是這樣的:

const comments = Comments.find({approved: true, city: {activeCity} }, {sort: {timestamp: -1}}).fetch();

但是,這並不工作,我究竟做錯了什麼?

回答

0

我已經設法解決這個問題。原來,而不是使用this.props我應該只是用道具來代替。

這是工作代碼:

const composer = (props, onData) => { 
 
    const subscription = Meteor.subscribe('comments'); 
 
    if (subscription.ready()) { 
 
    \t const activeCity = props.activeCity; 
 
    const comments = Comments.find({approved: true, city: activeCity }, {sort: {timestamp: -1}}).fetch(); 
 
    onData(null, { comments }); 
 
    } 
 
};

相關問題