In the React tutorial, I'm looking at the example.js
file
The file gets ments from a server in this function:
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
$.ajax({
url: this.props.url,
dataType: 'json',
cache: false,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
// Rest of CommentBox...
However, there is no require('jquery')
in the code. React doesn't list jQuery as a dependency. When I search for ajax
in the react repository there isn't any declaration of that function.
Is this $.ajax
function a react-specific function? Is it something other than jQuery? Thanks for any help to better understand how this part of React works!
In the React tutorial, I'm looking at the example.js
file
The file gets ments from a server in this function:
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
$.ajax({
url: this.props.url,
dataType: 'json',
cache: false,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
// Rest of CommentBox...
However, there is no require('jquery')
in the code. React doesn't list jQuery as a dependency. When I search for ajax
in the react repository there isn't any declaration of that function.
Is this $.ajax
function a react-specific function? Is it something other than jQuery? Thanks for any help to better understand how this part of React works!
-
2
$
is just a variable name, anyone can define it to be anything... – dandavis Commented Jun 30, 2015 at 21:47
2 Answers
Reset to default 7React DOES NOT require jQuery to work. If you look at this page from tutorial website(scroll a bit above) it is clearly mentioned that jQuery is included only to simplify.
Including the note here too
Note: We included jQuery here because we want to simplify the code of our future ajax calls, but it's NOT mandatory for React to work.
Also check out the plete section on getting started that has the main index html page which includes jQuery.
Hope this helps
its being required in the index.html
file. youll notice it gets required before the example.js file, which means jquery is available by the time the react code gets executed