77 * of patent rights can be found in the PATENTS file in the same directory.
88 */
99
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+
1019class CommentsBox extends React . Component {
1120 static propTypes = {
1221 initialComments : PropTypes . array . isRequired ,
13- page : PropTypes . number
22+ page : PropTypes . number ,
1423 } ;
1524
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 ,
2130 } ;
2231
23- loadMoreClicked = ( evt ) => {
32+ loadMoreClicked = evt => {
2433 var nextPage = this . state . page + 1 ;
2534 this . setState ( {
2635 page : nextPage ,
27- loadingMore : true
36+ loadingMore : true ,
2837 } ) ;
2938
3039 var url = evt . target . href ;
@@ -36,24 +45,23 @@ class CommentsBox extends React.Component {
3645 this . setState ( {
3746 comments : this . state . comments . concat ( data . comments ) ,
3847 hasMore : data . hasMore ,
39- loadingMore : false
48+ loadingMore : false ,
4049 } ) ;
4150 } ;
4251 xhr . send ( ) ;
4352 evt . preventDefault ( ) ;
4453 } ;
4554
4655 render ( ) {
47- var commentNodes = this . state . comments . map ( comment =>
56+ var commentNodes = this . state . comments . map ( comment => (
4857 < Comment author = { comment . Author } > { comment . Text } </ Comment >
49- ) ;
58+ ) ) ;
5059
5160 return (
5261 < div className = "comments" >
62+ < HooksDemo />
5363 < h1 > Comments</ h1 >
54- < ol className = "commentList" >
55- { commentNodes }
56- </ ol >
64+ < ol className = "commentList" > { commentNodes } </ ol >
5765 { this . renderMoreLink ( ) }
5866 </ div >
5967 ) ;
@@ -64,7 +72,10 @@ class CommentsBox extends React.Component {
6472 return < em > Loading...</ em > ;
6573 } else if ( this . state . hasMore ) {
6674 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+ >
6879 Load More
6980 </ a >
7081 ) ;
@@ -76,14 +87,15 @@ class CommentsBox extends React.Component {
7687
7788class Comment extends React . Component {
7889 static propTypes = {
79- author : PropTypes . object . isRequired
90+ author : PropTypes . object . isRequired ,
8091 } ;
8192
8293 render ( ) {
8394 return (
8495 < li >
8596 < Avatar author = { this . props . author } />
86- < strong > { this . props . author . Name } </ strong > { ': ' }
97+ < strong > { this . props . author . Name } </ strong >
98+ { ': ' }
8799 { this . props . children }
88100 </ li >
89101 ) ;
@@ -92,7 +104,7 @@ class Comment extends React.Component {
92104
93105class Avatar extends React . Component {
94106 static propTypes = {
95- author : PropTypes . object . isRequired
107+ author : PropTypes . object . isRequired ,
96108 } ;
97109
98110 render ( ) {
@@ -107,7 +119,11 @@ class Avatar extends React.Component {
107119 ) ;
108120 }
109121
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+ ) ;
112128 } ;
113129}
0 commit comments