7
7
* of patent rights can be found in the PATENTS file in the same directory.
8
8
*/
9
9
10
+ function HooksDemo ( ) {
11
+ let [ count , updateCount ] = React . useState ( 0 ) ;
12
+ return (
13
+ < button onClick = { ( ) => updateCount ( count + 1 ) } >
14
+ Click count: { count }
15
+ </ button >
16
+ ) ;
17
+ }
18
+
10
19
class CommentsBox extends React . Component {
11
20
static propTypes = {
12
21
initialComments : PropTypes . array . isRequired ,
13
- page : PropTypes . number
22
+ page : PropTypes . number ,
14
23
} ;
15
24
16
- state = {
17
- comments : this . props . initialComments ,
18
- page : this . props . page ,
19
- hasMore : true ,
20
- loadingMore : false
25
+ state = {
26
+ comments : this . props . initialComments ,
27
+ page : this . props . page ,
28
+ hasMore : true ,
29
+ loadingMore : false ,
21
30
} ;
22
31
23
- loadMoreClicked = ( evt ) => {
32
+ loadMoreClicked = evt => {
24
33
var nextPage = this . state . page + 1 ;
25
34
this . setState ( {
26
35
page : nextPage ,
27
- loadingMore : true
36
+ loadingMore : true ,
28
37
} ) ;
29
38
30
39
var url = evt . target . href ;
@@ -36,24 +45,23 @@ class CommentsBox extends React.Component {
36
45
this . setState ( {
37
46
comments : this . state . comments . concat ( data . comments ) ,
38
47
hasMore : data . hasMore ,
39
- loadingMore : false
48
+ loadingMore : false ,
40
49
} ) ;
41
50
} ;
42
51
xhr . send ( ) ;
43
52
evt . preventDefault ( ) ;
44
53
} ;
45
54
46
55
render ( ) {
47
- var commentNodes = this . state . comments . map ( comment =>
56
+ var commentNodes = this . state . comments . map ( comment => (
48
57
< Comment author = { comment . Author } > { comment . Text } </ Comment >
49
- ) ;
58
+ ) ) ;
50
59
51
60
return (
52
61
< div className = "comments" >
62
+ < HooksDemo />
53
63
< h1 > Comments</ h1 >
54
- < ol className = "commentList" >
55
- { commentNodes }
56
- </ ol >
64
+ < ol className = "commentList" > { commentNodes } </ ol >
57
65
{ this . renderMoreLink ( ) }
58
66
</ div >
59
67
) ;
@@ -64,7 +72,10 @@ class CommentsBox extends React.Component {
64
72
return < em > Loading...</ em > ;
65
73
} else if ( this . state . hasMore ) {
66
74
return (
67
- < a href = { '/comments/page-' + ( this . state . page + 1 ) } onClick = { this . loadMoreClicked } >
75
+ < a
76
+ href = { '/comments/page-' + ( this . state . page + 1 ) }
77
+ onClick = { this . loadMoreClicked }
78
+ >
68
79
Load More
69
80
</ a >
70
81
) ;
@@ -76,14 +87,15 @@ class CommentsBox extends React.Component {
76
87
77
88
class Comment extends React . Component {
78
89
static propTypes = {
79
- author : PropTypes . object . isRequired
90
+ author : PropTypes . object . isRequired ,
80
91
} ;
81
92
82
93
render ( ) {
83
94
return (
84
95
< li >
85
96
< Avatar author = { this . props . author } />
86
- < strong > { this . props . author . Name } </ strong > { ': ' }
97
+ < strong > { this . props . author . Name } </ strong >
98
+ { ': ' }
87
99
{ this . props . children }
88
100
</ li >
89
101
) ;
@@ -92,7 +104,7 @@ class Comment extends React.Component {
92
104
93
105
class Avatar extends React . Component {
94
106
static propTypes = {
95
- author : PropTypes . object . isRequired
107
+ author : PropTypes . object . isRequired ,
96
108
} ;
97
109
98
110
render ( ) {
@@ -107,7 +119,11 @@ class Avatar extends React.Component {
107
119
) ;
108
120
}
109
121
110
- getPhotoUrl = ( author ) => {
111
- return 'https://avatars.githubusercontent.com/' + author . GithubUsername + '?s=50' ;
122
+ getPhotoUrl = author => {
123
+ return (
124
+ 'https://avatars.githubusercontent.com/' +
125
+ author . GithubUsername +
126
+ '?s=50'
127
+ ) ;
112
128
} ;
113
129
}
0 commit comments