@@ -380,35 +380,35 @@ import { ReComponent, Update } from "react-recomponent";
380
380
381
381
type Props = {};
382
382
type State = { count: number, value: string };
383
- type Action = {| type: " CLICK" | } | {| type: " UPDATE_VALUE " , payload: string | };
383
+ type Action = { type: " CLICK" } | { type: " CHANGE " , payload: string };
384
384
385
385
class TypedActions extends ReComponent < Props, State, Action> {
386
- // NOTE: we use `this.send` API because it ensures type-safety for action's `payload`
386
+ // NOTE: We use `this.send()` API because it ensures type-safety for
387
+ // an action's `payload`.
387
388
handleClick = () => this .send ({ type: " CLICK" });
388
- handleUpdateValue = (newValue : string ) => this .send ({ type: " UPDATE_VALUE" , payload: newValue });
389
+ handleChange = (event : Event ) =>
390
+ this .send ({ type: " CHANGE" , payload: event .target .value });
389
391
390
- state = { count: 0 };
392
+ state = { count: 0 , value : " " };
391
393
392
394
static reducer (action , state ) {
393
395
switch (action .type ) {
394
396
case " CLICK" :
395
397
return Update ({ count: state .count + 1 });
396
- case " UPDATE_VALUE " :
398
+ case " CHANGE " :
397
399
return Update ({ value: action .payload });
398
- default : {
399
- return NoUpdate ();
400
400
}
401
401
}
402
402
}
403
403
404
404
render () {
405
405
return (
406
- < React . Fragment >
407
- < button onClick= {this .handleClick }>
408
- You’ve clicked this {this .state .count } times (s)
409
- < / button>
410
- < Input onValueChange = {this .handleValueUpdate } / >
411
- < React . Fragment / >
406
+ < div >
407
+ < button onClick= {this .handleClick }>
408
+ You’ve clicked this {this .state .count } times (s)
409
+ < / button>
410
+ < input value = {this .state . value } onChange = { this . handleChange } / >
411
+ < / div >
412
412
);
413
413
}
414
414
}
0 commit comments