【发布时间】:2020-06-21 21:32:48
【问题描述】:
在下面的例子中我收到了这个错误
TypeError: _this is undefined
我尝试了很多方法,但找不到修复错误的方法,我该如何解决?
component_for_home_page.js
import { dispatch } from 'dispatch'
class Home extends PureComponent {
componentDidMount() {
dispatch('ADD_TEXT', 'Beep, Boop')
// instead of following
// this.props.dispatch({
// type: 'ADD_TEXT'
// text: 'Beep, Boop'
// })
//
}
render() {
return (<p>{this.props.text}</p>)
}
}
function mapStateToProps(state) {
return {
...state
}
}
const connectedHomeComponent = connect(mapStateToProps)(Home)
export {
connectedHomeComponent
}
simplify_dispatch.js
const dispatch = (type, text) => {
return this.props.dispatch({
type,
text
})
}
【问题讨论】:
标签: javascript reactjs import binding export