File tree 2 files changed +27
-3
lines changed
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 6
6
"globals" : {
7
7
"React" : 0 ,
8
8
"Remarkable" : 0 ,
9
- "ReactDOM" : 0
9
+ "ReactDOM" : 0 ,
10
+ "$" : 0
10
11
},
11
12
"extends" : " eslint:recommended" ,
12
13
"parserOptions" : {
Original file line number Diff line number Diff line change 24
24
} ) ;
25
25
26
26
let CommentBox = React . createClass ( {
27
+ loadCommentsFromServer : function ( ) {
28
+ $ . ajax ( {
29
+ url : this . props . url ,
30
+ dataType : 'json' ,
31
+ cache : false ,
32
+ success : function ( data ) {
33
+ this . setState ( { data : data } ) ;
34
+ } . bind ( this ) ,
35
+ error : function ( xhr , status , err ) {
36
+ console . error ( this . props . url , status , err . toString ( ) ) ;
37
+ } . bind ( this )
38
+ } ) ;
39
+ } ,
40
+
41
+ getInitialState : function ( ) {
42
+ return { data : [ ] } ;
43
+ } ,
44
+
45
+ componentDidMount : function ( ) {
46
+ this . loadCommentsFromServer ( ) ;
47
+ setInterval ( this . loadCommentsFromServer , this . props . pollInterval ) ;
48
+ } ,
49
+
27
50
render : function ( ) {
28
51
return (
29
52
< div className = "commentBox" >
30
53
< h1 > Comments</ h1 >
31
- < CommentList data = { this . props . data } />
54
+ < CommentList data = { this . state . data } />
32
55
< CommentForm />
33
56
</ div >
34
57
) ;
62
85
}
63
86
} ) ;
64
87
ReactDOM . render (
65
- < CommentBox data = { data } /> ,
88
+ < CommentBox url = "/api/comments" pollInterval = { 2000 } /> ,
66
89
document . getElementById ( 'content' )
67
90
) ;
68
91
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments