【发布时间】:2018-08-23 16:08:08
【问题描述】:
刚从 react/redux 开始。尝试实现一个与动作挂钩的 Counter 组件:
export class Counter extends Component {
constructor(props) {
super(props);
}
handleClick = () => {
this.props.incrementCounter();
}
render() {
return (
<div onClick={this.handleClick}>
hello this is counter:{this.props.counter}
</div>
)
}
}
const mapStateToProps = (state) => ({
counter: state
})
export default connect(mapStateToProps, { incrementCounter })(Counter)
这是 index.js 的一部分:
ReactDOM.render(<Provider store={store}>
<App />
</Provider>, document.getElementById('root'));
但是,当我运行应用程序时,单击“hello”div 时出现错误?
错误: _this.props.incrementCounter 不是函数
为什么会出现这个错误,好像 props 没有正确传递?
更多代码见:github
【问题讨论】:
标签: javascript reactjs react-redux