Created
July 23, 2019 12:20
-
-
Save takahirohonda/408c9385f443d4cb8a592de0c129a2ff to your computer and use it in GitHub Desktop.
refactoring-react-es6-class-components-with-property-initialisers-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Form extends ReactComponents { | |
state = {id: ''} | |
submitHandler = () => { | |
// do more things here .... | |
// then dispatch action | |
this.props.onSubmitHandler() | |
} | |
nameInputHandler = (e) => { | |
// to dispatch action (redux) | |
this.props.onNameChangeHandler(e.target.value) | |
} | |
idInputHandler = (e) => { | |
// update local state | |
this.setState({id: e.target.value}) | |
} | |
render() { | |
return ( | |
<form> | |
<label for="firstname">First name</label> | |
<input | |
type="text" name="firstname" id="firstname" | |
onChange={this.nameInputHandler} | |
/> | |
<label for="id">Id</label> | |
<input | |
type="text" name="firstname" id="firstname" | |
onChange={this.idInputHandler} | |
/> | |
<button type="submit" onSubmit={this.submitHandler}> | |
Submit | |
</button> | |
</form> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment