【发布时间】:2019-04-01 10:00:38
【问题描述】:
在组件级别链接依赖异步 redux thunk 操作的推荐方法是什么?
我的用例是一个流程,我需要首先进行 api 调用以检索用户对象,然后获取该用户的所有博客文章。需要注意的是,第二次获取所有博客文章的调用取决于第一次调用的返回值(用户 ID)。
我的组件:
export default class UserDetail extends React.Component
{
componentDidMount() {
this.props.getUser()
}
}
this.props.getUser() 返回一个我映射到道具的用户对象:
const mapStateToProps = (state) => {
return {
user: state.user
}
}
我需要在this.props.getUser() 完成后致电this.props.getBlogPostsForUser(USER_ID)。以这种方式链接操作的推荐最佳做法是什么?
【问题讨论】:
标签: javascript reactjs redux redux-thunk