Last active
June 29, 2020 21:04
-
-
Save StevenJL/cb9be3eaa050bc3f38680fdc499d0fe0 to your computer and use it in GitHub Desktop.
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
class ControlledComponent extends React.Component { | |
constructor( props) { | |
super(props) | |
this.state = { | |
name: 'Firstname Lastname', | |
email: '[email protected]', | |
password: '' | |
} | |
this.handleChange = this.handleChange.bind(this) | |
this.handleSubmit = this.handleSubmit.bind(this) | |
} | |
handleChange({ target }) { | |
this.setState({ | |
[target.name]: target.value | |
}) | |
} | |
handleSubmit(event) { | |
event.preventDefault() | |
const { name, email, password } = this.state; | |
this.props.createAccount( | |
name: name, | |
email: email, | |
password: password | |
) | |
} | |
render() { | |
return ( | |
<form onSubmit ={this.handleSubmit}> | |
<input type="text" name="name" value={this.state.name} onChange={this.handleChange} /> | |
<input type="text" name="email" value={this.state.email} onChange={this.handleChange} /> | |
<input type="password" name="password" value={this.state.password} onChange={this.handleChange} /> | |
<button>Submit</button> | |
</form> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment