Created
May 9, 2017 00:25
-
-
Save evanharmon/5d032355d0e34d2553ea04fdab167213 to your computer and use it in GitHub Desktop.
Example login form vanilla react
This file contains hidden or 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'; | |
| class LoginForm extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| email: '', | |
| password: '' | |
| }; | |
| } | |
| handleEmailChange(e) { | |
| this.setState({ email: e.target.value }); | |
| } | |
| handlePasswordChange(e) { | |
| this.setState({ password: e.target.value }); | |
| } | |
| handleSubmit(e) { | |
| alert('submitted!'); | |
| } | |
| render() { | |
| return ( | |
| <form onSubmit={this.handleSubmit.bind(this)}> | |
| <input type="text" | |
| value={this.state.email} | |
| placeholder="Email" | |
| onChange={this.handleEmailChange.bind(this)} /> | |
| <input type="password" | |
| value={this.state.password} | |
| placeholder="Password" | |
| onChange={this.handlePasswordChange.bind(this)} /> | |
| <input type="submit" value="Log In"/> | |
| </form> | |
| ); | |
| } | |
| } | |
| export default LoginForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this, it was helpful.