I use this to method to work with component, the componentWillMount to initialize data for homepage and the componentWillReceiveProps when router change (category page), but when I come back home page from category page, I know because componentWillMount just do one time so I cannot see data.
componentWillMount(){
this.props.fetchBooks(1)
}
componentWillReceiveProps(nextProps){
if(nextProps.match.params.id && nextProps.match.params.id !== this.props.match.params.id){
this.props.fetchBookByCategory(nextProps.match.params.id)
}
}
I put this initialized code to componentWillReceiveProps, It works but It calls the fetchBooks(1) constantly eventhough I tried to do with some condition, please help me this problems, many thanks.