Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 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. handleChange = e => {
  21. const { name, value } = e.target;
  22. this.setState({
  23. [name]: value
  24. });
  25. };
  26.  
  27. render() {
  28. const { username, password } = this.state;
  29. return (
  30. <div>
  31. <h1>Login</h1>
  32. <form onSubmit={this.handleSubmit}>
  33. <div className="form-group">
  34. <label htmlFor="username">Username</label>
  35. <input
  36. value={username}
  37. name="username"
  38. onChange={this.handleChange}
  39. id="username"
  40. type="text"
  41. className="form-control"
  42. />
  43. </div>
  44. <div className="form-group">
  45. <label htmlFor="password">Password</label>
  46. <input
  47. value={password}
  48. name="password"
  49. onChange={this.handleChange}
  50. id="password"
  51. type="password"
  52. className="form-control"
  53. />
  54. </div>
  55. <button className="btn btn-primary">Login</button>
  56. </form>
  57. </div>
  58. );
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement