Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import React, { Component } from "react";
  2.  
  3. export default class LoginForm extends Component {
  4. state = {
  5. username: "",
  6. password: ""
  7. };
  8.  
  9. handleSubmit = e => {
  10. e.preventDefault();
  11. console.log("Submitted");
  12. };
  13.  
  14. handleChange = input => e => {
  15. this.setState({
  16. [input]: e.target.value
  17. });
  18. };
  19.  
  20. render() {
  21. const { username, password } = this.state;
  22. return (
  23. <div>
  24. <h1>Login</h1>
  25. <form onSubmit={this.handleSubmit}>
  26. <div className="form-group">
  27. <label htmlFor="username">Username</label>
  28. <input
  29. value={username}
  30. name="username"
  31. onChange={this.handleChange("username")}
  32. id="username"
  33. type="text"
  34. className="form-control"
  35. />
  36. </div>
  37. <div className="form-group">
  38. <label htmlFor="password">Password</label>
  39. <input
  40. value={password}
  41. name="password"
  42. onChange={this.handleChange("password")}
  43. id="password"
  44. type="password"
  45. className="form-control"
  46. />
  47. </div>
  48. <button className="btn btn-primary">Login</button>
  49. </form>
  50. </div>
  51. );
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement