Last active
April 1, 2019 06:34
-
-
Save agoiabel/c84c3c33fc9f31de0e7e2c394e749fcf to your computer and use it in GitHub Desktop.
This file contains 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 FormContainer extends Component { | |
constructor () { | |
this.state = { | |
formControls: { | |
email: { | |
value: '' | |
}, | |
name: { | |
value: '' | |
}, | |
password: { | |
value: '' | |
} | |
} | |
} | |
} | |
changeHandler = event => { | |
const name = event.target.name; | |
const value = event.target.value; | |
this.setState({ | |
formControls: { | |
...this.state.formControls, | |
[name]: { | |
...this.state.formControls[name], | |
value | |
} | |
} | |
}); | |
} | |
render() { | |
return ( | |
<form> | |
<input type="email" | |
name="email" | |
value={this.state.formControls.email.value} | |
onChange={this.changeHandler} | |
/> | |
<input type="text" | |
name="name" | |
value={this.state.formControls.name.value} | |
onChange={this.changeHandler} | |
/> | |
<input type="password" | |
name="password" | |
value={this.state.formControls.password.value} | |
onChange={this.changeHandler} | |
/> | |
</form> | |
); | |
} | |
} | |
export default FormContainer; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is not working.
because you have got object inside
email
, sovalue
will replace whole object.