Hi I just want to receive ajax request, but the problem is that jquery is not defined in React. React version is 14.0
Uncaught ReferenceError: $ is not defined
I have two files :
index.js
import React from 'react'; import { render } from 'react-dom'; import App from './containers/App'; const root = document.getElementById('root'); render( <App source='https://api.github.com/users/octocat/gists' />, root );
app.js
import React, { Component } from 'react'; export default class App extends Component { componentDidMount() { const { source } = this.props; console.log($); // throws error } render() { return ( <h1>Hey there.</h1> ); } }
Yes, we can use jQuery in ReactJs.
The React. js error "X is not defined react/jsx-no-undef" occurs when we forget to import a function, class or a variable in our code before using it. To solve the error, make sure to import the value before using it in your code, e.g. import {myFunc} from 'my-package' . Copied!
You may experience the “jQuery is not defined error” when jQuery is included but not loaded. Make sure that it's loaded by finding the script source and pasting the URL in a new browser or tab. The snippet of text you should look for to find the URL to test.
Try add jQuery
to your project, like
npm i jquery --save
or if you use bower
bower i jquery --save
then
import $ from 'jquery';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With