Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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>
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement