javascript - 反应错误:无法读取未定义的属性“上下文”
问题描述
我想访问组件中的上下文,但出现此错误:
未捕获的类型错误:无法读取未定义的属性“上下文”
var React = require('react'),
var ReactIntl = require('react-intl');
class ContactSearch extends React.Component {
constructor(props) {
super(props);
}
_handleFormSubmit(e) {
if (this.context.router) { //I can't access this.context in here
e.preventDefault();
......
}
}
render() {
return (
<div className="search-container">
{this.renderSearch()}
</div>
);
}
}
ContactSearch.propTypes = {};
ContactSearch.defaultProps = {};
module.exports = ReactIntl.injectIntl(ContactSearch);
我能得到一些关于为什么 this.context 不存在的帮助吗?
谢谢!