Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe1b554

Browse files
chenglousophiebits
authored andcommitted
[Docs] Fix tutorial line highlights, revert ajax in cb
(cherry picked from commit 66d6e3f)
1 parent 0ecf9f0 commit fe1b554

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

docs/docs/tutorial.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ React.renderComponent(
301301

302302
Now that the data is available in the `CommentList`, let's render the comments dynamically:
303303

304-
```javascript{4-6,9}
304+
```javascript{4-10,13}
305305
// tutorial10.js
306306
var CommentList = React.createClass({
307307
render: function() {
@@ -475,7 +475,7 @@ var CommentForm = React.createClass({
475475

476476
Let's make the form interactive. When the user submits the form, we should clear it, submit a request to the server, and refresh the list of comments. To start, let's listen for the form's submit event and clear it.
477477

478-
```javascript{3-13,16-17,21}
478+
```javascript{3-13,16-18}
479479
// tutorial16.js
480480
var CommentForm = React.createClass({
481481
handleSubmit: function() {
@@ -517,7 +517,7 @@ When a user submits a comment, we will need to refresh the list of comments to i
517517

518518
We need to pass data from the child component to its parent. We do this by passing a `callback` in props from parent to child:
519519

520-
```javascript{15-17,31}
520+
```javascript{15-17,30}
521521
// tutorial17.js
522522
var CommentBox = React.createClass({
523523
loadCommentsFromServer: function() {
@@ -651,22 +651,18 @@ var CommentBox = React.createClass({
651651
handleCommentSubmit: function(comment) {
652652
var comments = this.state.data;
653653
var newComments = comments.concat([comment]);
654-
this.setState({data: newComments}, function() {
655-
// `setState` accepts a callback. To avoid (improbable) race condition,
656-
// `we'll send the ajax request right after we optimistically set the new
657-
// `state.
658-
$.ajax({
659-
url: this.props.url,
660-
dataType: 'json',
661-
type: 'POST',
662-
data: comment,
663-
success: function(data) {
664-
this.setState({data: data});
665-
}.bind(this),
666-
error: function(xhr, status, err) {
667-
console.error(this.props.url, status, err.toString());
668-
}.bind(this)
669-
});
654+
this.setState({data: newComments});
655+
$.ajax({
656+
url: this.props.url,
657+
dataType: 'json',
658+
type: 'POST',
659+
data: comment,
660+
success: function(data) {
661+
this.setState({data: data});
662+
}.bind(this),
663+
error: function(xhr, status, err) {
664+
console.error(this.props.url, status, err.toString());
665+
}.bind(this)
670666
});
671667
},
672668
getInitialState: function() {

0 commit comments

Comments
 (0)