Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  4] [ 4]  / answers: 1 / hits: 157474  / 9 Years ago, mon, october 26, 2015, 12:00:00

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>
);
}
}

More From » jquery

 Answers
1

Try add jQuery to your project, like



npm i jquery --save


or if you use bower



bower i jquery --save


then



import $ from 'jquery'; 

[#64598] Friday, October 23, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marib

Total Points: 596
Total Questions: 120
Total Answers: 95

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
;