【发布时间】:2017-11-01 23:38:06
【问题描述】:
我正在 react 中的一个 userProfile 容器组件,它在从服务器获取数据后显示一些数据。
这是组件:
import React from 'react';
import {connect} from 'react-redux';
import PersonalInformationView from './PersonalInformationView';
import * as selectors from '../../../reducers';
class PersonalInformationViewContainer extends React.Component{
constructor(props, context){
super(props, context);
}
render(){
return (
<PersonalInformationView userProfile={this.props.userProfile}/>
);
}
}
const mapStateToProps = (state, ownProps) => {
return {
user: selectors.getUser(state),
userProfile: selectors.getUserProfile(state)
};
};
const mapDispatchToProps = () =>{
return {
};
};
export default connect(mapStateToProps, mapDispatchToProps)(PersonalInformationViewContainer);
我遇到的问题是我需要调用 FETCH_USER_PROFILE_STARTED 调用 saga 并带来数据的动作。这需要在调用选择器 getUserProfile 之前完成,因为上面的代码结果是未定义的。
确保我已完成数据获取的最佳方法是什么,以便我的组件中没有未定义 props.userProfile?
【问题讨论】:
标签: reactjs react-redux redux-saga