creamidea / creamidea.github.com

冰糖火箭筒&&蜂蜜甜甜圈
https://creamidea.github.io/
4 stars 4 forks source link

[Redux] this.props.dispatch is undefined in componentDidMount #22

Closed creamidea closed 7 years ago

creamidea commented 7 years ago

When you use connect, please don't transfer mapDispatchToProps( the second optional param of connect), which overwrite this.props.dispatch in componentDidMount.

For example, the right way:

class ListContainer extends Component {

  constructor (props) {
    super(props)
  }

  componentDidMount () {
    const { dispatch } = this.props
    dispatch(fetchIssues(1, 25))
  }

  render () {
    return <IssueList {...this.props} />
  }
}

const VisibleIssueList = connect(
  mapStateToProps
// please don't transfer the `mapDispatchToProps `
)(ListContainer)