사용자 프로필을 표시하는 Profile
구성 요소가 있습니다. user/:userId
노선 변화에서 userId
쿼리 PARAM은 react-router-redux
에 ownProps
덕분에 업데이트됩니다 다음 프레젠테이션의 구성 요소에 전달됩니다 :이 시점에서redux-react에서 url이 변경 될 때 업데이트 상태가
const mapStateToProps = (state, ownProps) => ({
userId: ownProps.params.userId,
user: store.profile.user //null at first, will be updated later
})
, 나는 userId
에서 사용자 프로필을 가져올 필요가있다. 이 가져 오기는 어디에서해야합니까? 사용자가 /users/1
에서 /users/2
, componentDidMount
습관 트리거로 이동하면 현재 내가 componentDidMount
componentDidMount() {
this.props.fetchProfile(this.props.userId) //this will dispatch an action to fetch user details and store in `store.profile.user`
}
이의 단점을 그 일을하고 같습니다. 어떻게해야합니까?