File tree 1 file changed +13
-17
lines changed
1 file changed +13
-17
lines changed Original file line number Diff line number Diff line change @@ -40,23 +40,19 @@ var CommentBox = React.createClass({
40
40
} ,
41
41
handleCommentSubmit : function ( comment ) {
42
42
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 )
60
56
} ) ;
61
57
} ,
62
58
getInitialState : function ( ) {
You can’t perform that action at this time.
0 commit comments