Skip to content

Commit

Permalink
Updating example.js to match tutorial
Browse files Browse the repository at this point in the history
example.js was out of sync with the tutorial; handleCommentSubmit does not need a call back.
  • Loading branch information
ajdinhedzic committed Aug 24, 2015
1 parent a8c9f89 commit f09e48c
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions public/scripts/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ var CommentBox = React.createClass({
},
handleCommentSubmit: function(comment) {
var comments = this.state.data;
comments.push(comment);
this.setState({data: comments}, function() {
// `setState` accepts a callback. To avoid (improbable) race condition,
// we'll send the ajax request right after we optimistically set the new
// state.
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'POST',
data: comment,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
var newComments = comments.concat([comment]);
this.setState({data: newComments});
$.ajax({
url: this.props.url,
dataType: 'json',
type: 'POST',
data: comment,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
getInitialState: function() {
Expand Down

0 comments on commit f09e48c

Please sign in to comment.