H5W3
当前位置:H5W3 > 问答 > 正文

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

Answer

Try add jQuery to your project, like

npm i jquery --save

or if you use bower

bower i jquery --save

then

import $ from 'jquery'; 

本文地址:H5W3 » Jquery in React is not defined

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址