1

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!

kevin
  • 51
  • 6
  • 3
    It's an event handler and it's not properly bound. (There are multiple duplicates, and it's also searchable on the web--very common beginner issue.) – Dave Newton Jan 06 '20 at 17:43

0 Answers0