1
我有一个显示用户配置文件的Profile
组件。在路线改变user/:userId
的userId
查询参数将在ownProps
由于更新到react-router-redux
和将被传递到我的演示组件:URL更改时的更新状态还原反应
const mapStateToProps = (state, ownProps) => ({
userId: ownProps.params.userId,
user: store.profile.user //null at first, will be updated later
})
在这一点上,我需要从userId
获取用户配置文件。我应该在哪里抓取?目前,我在componentDidMount
componentDidMount() {
this.props.fetchProfile(this.props.userId) //this will dispatch an action to fetch user details and store in `store.profile.user`
}
做它的这种方法的缺点是,如果用户从去到/users/1
/users/2
,componentDidMount
不会触发。这应该怎么做?