Created
March 29, 2019 06:55
-
-
Save chriskavanagh/cbe074e22ca78f23c3f70d064b2d365e 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
import React, { Component } from "react"; | |
export default class LoginForm extends Component { | |
state = { | |
username: "", | |
password: "" | |
}; | |
handleSubmit = e => { | |
e.preventDefault(); | |
console.log("Submitted"); | |
}; | |
handleChange = input => e => { | |
this.setState({ | |
[input]: e.target.value | |
}); | |
}; | |
render() { | |
const { username, password } = this.state; | |
return ( | |
<div> | |
<h1>Login</h1> | |
<form onSubmit={this.handleSubmit}> | |
<div className="form-group"> | |
<label htmlFor="username">Username</label> | |
<input | |
value={username} | |
name="username" | |
onChange={this.handleChange("username")} | |
id="username" | |
type="text" | |
className="form-control" | |
/> | |
</div> | |
<div className="form-group"> | |
<label htmlFor="password">Password</label> | |
<input | |
value={password} | |
name="password" | |
onChange={this.handleChange("password")} | |
id="password" | |
type="password" | |
className="form-control" | |
/> | |
</div> | |
<button className="btn btn-primary">Login</button> | |
</form> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment