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

Skip to content

Commit f09e48c

Browse files
committed
Updating example.js to match tutorial
example.js was out of sync with the tutorial; handleCommentSubmit does not need a call back.
1 parent a8c9f89 commit f09e48c

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

public/scripts/example.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,19 @@ var CommentBox = React.createClass({
4040
},
4141
handleCommentSubmit: function(comment) {
4242
var comments = this.state.data;
43-
comments.push(comment);
44-
this.setState({data: comments}, function() {
45-
// `setState` accepts a callback. To avoid (improbable) race condition,
46-
// we'll send the ajax request right after we optimistically set the new
47-
// state.
48-
$.ajax({
49-
url: this.props.url,
50-
dataType: 'json',
51-
type: 'POST',
52-
data: comment,
53-
success: function(data) {
54-
this.setState({data: data});
55-
}.bind(this),
56-
error: function(xhr, status, err) {
57-
console.error(this.props.url, status, err.toString());
58-
}.bind(this)
59-
});
43+
var newComments = comments.concat([comment]);
44+
this.setState({data: newComments});
45+
$.ajax({
46+
url: this.props.url,
47+
dataType: 'json',
48+
type: 'POST',
49+
data: comment,
50+
success: function(data) {
51+
this.setState({data: data});
52+
}.bind(this),
53+
error: function(xhr, status, err) {
54+
console.error(this.props.url, status, err.toString());
55+
}.bind(this)
6056
});
6157
},
6258
getInitialState: function() {

0 commit comments

Comments
 (0)