Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery in React is not defined

Hi I just want to receive ajax request, but the problem is that jquery is not defined in React. React version is 14.0

Error message

 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>         );     } } 
like image 800
Machycek Avatar asked Oct 26 '15 16:10

Machycek


People also ask

Can we use jQuery in React?

Yes, we can use jQuery in ReactJs.

Is not defined JavaScript React?

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!

Is not defined in jQuery?

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.


1 Answers

Try add jQuery to your project, like

npm i jquery --save 

or if you use bower

bower i jquery --save 

then

import $ from 'jquery';  
like image 92
Oleksandr T. Avatar answered Sep 17 '22 15:09

Oleksandr T.