Created
March 29, 2019 06:56
-
-
Save chriskavanagh/e6dec80074647ed55ebd972edb39e2d7 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 | |
}); | |
}; */ | |
handleChange = e => { | |
const { name, value } = e.target; | |
this.setState({ | |
[name]: 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} | |
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} | |
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