treb
treb

Reputation: 548

Uncaught Reference Error: $ is not defined (Reactjs)

what could be the reason of this error?

this is my code

componentDidMount() {
    $.get("/api/v1/schools", function(result) {
        this.setState({
            dataSchools: result,
        });
    }.bind(this));
}

Upvotes: 0

Views: 1120

Answers (1)

Kishore Barik
Kishore Barik

Reputation: 770

Note: I am not recommending use of jquery only for ajax calls in ReactJs application. You can use libraries like superagent or needle etc.

Coming to your error: that jquery is not identified inside your JSX code. The reason is JS script inclusion precedence. Make sure you are including the jQuery library ahead of your bundle Js(the Js generated using your buldlers like webpack or CommonJs). To be in safer side keep the script to include the jQuery library before all other libraries. Because there are many other library which depend upon jQuery to function properly.

Hope this helps.

Upvotes: 1

Related Questions