componentDidMount not running after calling browserHistory.push("/url")
@codyc4321 try self.props.router.push('/url')
don't put API calls in a component lifecycle.
create an action
function getUserInfo(payload) {
// do axios
return {
type: 'GET_USER_INFO',
payload: result_of_your_api_call,
error: false/true
};
}
create reducer for this action and mutate state in reducer
after that, you need to matStateToProps and mapDispatchToProps
connect(mapStateToProps, mapDispatchToProps)(YourMagicComponent)
that connects your component and your redux
After that, you get a redux state in your component. For more information please read this http://redux.js.org/docs/basics/ExampleTodoList.html
Remember 1. when component initialized it hasn't any data in props except defaultProps. 2. componentDidMount doesn't know anything outside component (available only default props and props defined before component mounted) 3. if you need to do something in componentWillUpdate you need to define rules for update that's component
componentWillUpdate(nextProps) {
this.setState(key: nextProps.key)
}
shouldComponentUpdate(nextProps, nextState) {
// fix for your update
if (this.state.key !== nextProps.key) {
return true;
}
}