@@ -13,41 +13,40 @@ interface State {
1313 count : number ;
1414}
1515
16- export class StatefulCounterWithDefault extends React . Component < StatefulCounterWithDefaultProps , State > {
17- // to make defaultProps strictly typed we need to explicitly declare their type
18- // @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11640
19- static defaultProps : DefaultProps = {
20- initialCount : 0 ,
21- } ;
22-
23- props : StatefulCounterWithDefaultProps & DefaultProps ;
16+ export const StatefulCounterWithDefault : React . ComponentClass < StatefulCounterWithDefaultProps > =
17+ class extends React . Component < StatefulCounterWithDefaultProps & DefaultProps > {
18+ // to make defaultProps strictly typed we need to explicitly declare their type
19+ // @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11640
20+ static defaultProps : DefaultProps = {
21+ initialCount : 0 ,
22+ } ;
23+
24+ state : State = {
25+ count : this . props . initialCount ,
26+ } ;
27+
28+ componentWillReceiveProps ( { initialCount } : StatefulCounterWithDefaultProps ) {
29+ if ( initialCount != null && initialCount !== this . props . initialCount ) {
30+ this . setState ( { count : initialCount } ) ;
31+ }
32+ }
2433
25- state : State = {
26- count : this . props . initialCount ,
27- } ;
34+ handleIncrement = ( ) => {
35+ this . setState ( { count : this . state . count + 1 } ) ;
36+ }
2837
29- componentWillReceiveProps ( { initialCount } : StatefulCounterWithDefaultProps ) {
30- if ( initialCount != null && initialCount !== this . props . initialCount ) {
31- this . setState ( { count : initialCount } ) ;
38+ render ( ) {
39+ const { handleIncrement } = this ;
40+ const { label } = this . props ;
41+ const { count } = this . state ;
42+
43+ return (
44+ < div >
45+ < span > { label } : { count } </ span >
46+ < button type = "button" onClick = { handleIncrement } >
47+ { `Increment` }
48+ </ button >
49+ </ div >
50+ ) ;
3251 }
33- }
34-
35- handleIncrement = ( ) => {
36- this . setState ( { count : this . state . count + 1 } ) ;
37- }
38-
39- render ( ) {
40- const { handleIncrement } = this ;
41- const { label } = this . props ;
42- const { count } = this . state ;
43-
44- return (
45- < div >
46- < span > { label } : { count } </ span >
47- < button type = "button" onClick = { handleIncrement } >
48- { `Increment` }
49- </ button >
50- </ div >
51- ) ;
52- }
53- }
52+ } ;
0 commit comments