Advertisement
Guest User

Untitled

a guest
Jul 9th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class LoginForm extends React.Component {
  2.  
  3.     state = { name: '', password: '' };
  4.  
  5.     handleNameChange(e) {
  6.         this.setState({ name: e.target.value });
  7.     }
  8.  
  9.     handlePasswordChange(e) {
  10.         this.setState({ password: e.target.value });
  11.     }
  12.  
  13.     handleSubmit = (e) => {
  14.         e.preventDefault();
  15.         const name = this.state.name.trim();
  16.         const password = this.state.password.trim();
  17.         if (!name || !password) {
  18.             return;
  19.         }
  20.         this.props.onUserSubmit({ name, password });
  21.         this.setState({ name: '', password: '' });
  22.     }
  23.  
  24.  
  25.     render() {
  26.         return (
  27.             <form onSubmit={this.handleSubmit.bind(this)}>
  28.                 <h1>Login form</h1>
  29.                 <h4>Username:</h4>
  30.                 <input type="text" placeholder="Enter your name" onChange={this.handleNameChange.bind(this)} />
  31.                 <h4>Password:</h4>
  32.                 <input type="password" placeholder="Enter your password" onChange={this.handlePasswordChange.bind(this)} />
  33.                 <br />
  34.                 <br />
  35.                 <input type="submit" value="Login" name="Login" />
  36.             </form>
  37.             );
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement