react 在container里已经注入数据,为何在props没有?

新手上路,请多包涵
//container
import { connect } from 'react-redux'
import FollowerGroupNewForm from '../../components/_forms/FollowerGroupNewForm'
import { getTags } from '../../actions/tags'

const mapDispatchToProps = dispatch => {
  return ({
    getTags: () => dispatch(getTags())
  })
}

const mapStateToProps = state => {
  return ({
    authInfo: state.authInfo,
    hi: 'hi'
  })
}

export default connect(mapStateToProps, mapDispatchToProps)(FollowerGroupNewForm)
//component
  componentDidMount () {
    const { props: { getTags } } = this
    console.log(this.props)
    getTags().then(data => {
      const tags = data.map(tag => ({
        value: tag.name,
        label: tag.name
      }))

      this.setState({ tags: tags })
    })
  }

getTags 为 undefined, 没找到原因,求助!

阅读 2.4k
1 个回答

试试看这样:

import {bindActionCreators} from 'redux'
const mapDispatchToProps = dispatch => {
  return ({
    getTags: () => bindActionCreators(getTags,dispatch)
  })
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题