-
-
Save jrhii/23dd947bbf2e82a7ab8c1ea70a7faa75 to your computer and use it in GitHub Desktop.
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 NameForm extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {username: '', password: ''}; | |
this.handleChange = this.handleChange.bind(this); | |
this.handleSubmit = this.handleSubmit.bind(this); | |
} | |
handleChange(event) { | |
this.setState({username: event.target.value}); | |
} | |
handleSubmit(event) { | |
alert('A name was submitted: ' + this.state.username); | |
event.preventDefault(); | |
} | |
render() { | |
return ( | |
<form onSubmit={this.handleSubmit}> | |
<input type="text" placeholder="username" value={this.state.username} onChange={this.handleChange} required="required"/> | |
<input type="text" placeholder="password" value={this.state.password} onChange={this.handleChange} required="required"/> | |
<input type="submit" value="Submit"/> | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment