This question already has an answer here:
I want to access the context in my component, but I get this error:
Uncaught TypeError: Cannot read property 'context' of undefined
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);
Can I get some help about why this.context doesn't exist?
Thanks!