我正在嘗試創建一個容器,該容器從名爲ProfileCandidate
的集合中加載用戶詳細信息。我使用propTypes,我不確定我在做什麼錯誤。我相信這是一個加載順序錯誤,因爲我的propType加載了一個空對象。我知道容器正在運行,因爲它正在訂閱我的profileCandidate.private
請求。PropType不填充
路徑:components/ContactDetails.js
class ContactDetails extends React.Component {
constructor(props) {
super(props);
var ProfileCandidate = this.props.profileCandidate;
console.log("ProfileCandidate: ", this.props.profileCandidate);
};
}
ContactDetails.propTypes = {
profileCandidate: React.PropTypes.object.isRequired,
};
export default createContainer(() => {
Meteor.subscribe('profileCandidate.private');
var test = ProfileCandidate.findOne({userId: Meteor.userId()});
console.log("test: ", test);
return {
profileCandidate: ProfileCandidate.findOne({userId: Meteor.userId()}) || {},
};
}, ContactDetails)
你是否試圖渲染視圖?預計組件構建時會得到空對象,因爲發佈沒有時間向客戶端發送數據。不要期望構造函數中的'props'包含只在稍後重新運行容器後纔可用於'render'的數據。 – MasterAM