Skip to content

Instantly share code, notes, and snippets.

@jrhii
Created January 17, 2017 01:19
Show Gist options
  • Save jrhii/23dd947bbf2e82a7ab8c1ea70a7faa75 to your computer and use it in GitHub Desktop.
Save jrhii/23dd947bbf2e82a7ab8c1ea70a7faa75 to your computer and use it in GitHub Desktop.
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