我在使用Redux时遇到了一些问题,因为我正试图用connect()包装我。考虑所有导入有效(因为它们)。这是源代码以及输出错误。
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);
答案 0 :(得分:4)
您的导入之一实际上是不有效:
import { connect, bindActionCreators } from 'react-redux'
bindActionCreators
是redux
的一部分,而不是react-redux
。
所以你应该
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'