连接组件不正确渲染道具

时间:2016-06-22 12:02:42

标签: reactjs redux

我在使用Redux时遇到了一些问题,因为我正试图用connect()包装我。考虑所有导入有效(因为它们)。这是源代码以及输出错误。 bad error :((

import React, { Component } from 'react'
import { connect, bindActionCreators } from 'react-redux'
import * as counterActionCreators from '../core/actionCreators/count'

class CounterEgg extends Component {
  render() {
    const { onIncrement, store } = this.props
    let { value } = this.props
    value = store.getState()

    return (
      <div>
        Clicked: {value} times
        {' '}
        <button onClick={onIncrement}>
          +
        </button>
      </div>
    )
  }
}
function mapDispatchToProps(dispatch) {
  return {
    onIncrement: bindActionCreators(counterActionCreators, dispatch)
  }
}

export default connect(null, mapDispatchToProps)(CounterEgg);

1 个答案:

答案 0 :(得分:4)

您的导入之一实际上是有效:

import { connect, bindActionCreators } from 'react-redux'

bindActionCreatorsredux的一部分,而不是react-redux

所以你应该

import { connect } from 'react-redux'

import { bindActionCreators } from 'redux'