I'm stuck and don't understand what happens. I have 2 similar codes (look below). First works fine. But second gives error (codes minimized):
Unhandled Rejection (TypeError): self.loadCustomersAction is not a function
First (works fine):
...
import { loadCustomers } from '../../actions'
export class Component extends React.Component {
componentDidMount() {
this.props.loadCustomersAction()
}
render() {
return (
...
)
}
}
const mapDispatchToProps = dispatch => {
return {
loadCustomersAction: () => dispatch(loadCustomers())
}
}
export default connect(
...,
mapDispatchToProps
)(withRouter(Component))
Second (gives error):
import { loadCustomers } from '../../actions'
export class Component2 extends React.Component {
render() {
return (
...
<PrimaryButton onClick={this._handleSubmit} text="Add" />
...
)
}
_handleSubmit = () => {
var self = this
axiosWithProgress.post(...).then((response) => {
self.props.loadCustomersAction() // error here
})
}
}
const mapDispatchToProps = dispatch => {
return {
loadCustomersAction: () => dispatch(loadCustomers())
}
}
export default connect(
null,
mapDispatchToProps
)(withRouter(Component2))
Who can tell me what wrong? I tried almost all options from google and stackoverflow, but unsuccessfully.
UPD: changing self.props.loadCustomersAction()
to this.props.loadCustomersAction()
don't solve problem.
UPD: passing ownProps in mapDispatchToProps too.