@@ -380,35 +380,35 @@ import { ReComponent, Update } from "react-recomponent";
380380
381381type Props = {};
382382type State = { count: number, value: string };
383- type Action = {| type: " CLICK" | } | {| type: " UPDATE_VALUE " , payload: string | };
383+ type Action = { type: " CLICK" } | { type: " CHANGE " , payload: string };
384384
385385class 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`.
387388 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 });
389391
390- state = { count: 0 };
392+ state = { count: 0 , value : " " };
391393
392394 static reducer (action , state ) {
393395 switch (action .type ) {
394396 case " CLICK" :
395397 return Update ({ count: state .count + 1 });
396- case " UPDATE_VALUE " :
398+ case " CHANGE " :
397399 return Update ({ value: action .payload });
398- default : {
399- return NoUpdate ();
400400 }
401401 }
402402 }
403403
404404 render () {
405405 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 >
412412 );
413413 }
414414}
0 commit comments