Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72443

React error: Cannot read property 'context' of undefined [duplicate]

$
0
0

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!


Viewing all articles
Browse latest Browse all 72443

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>