我正在尝试创建一个容器,该容器从名为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