I have a component and the following state:
this.state = {
form : {
name : '',
username: '',
email: '',
phone: '',
address: {
street: '',
suite: '',
city: '',
zipcode: ''
}
}
}
In the form fields, I use the following method in onChange:
handleChange(e) {
const {name, value} = e.target;
let copyState = Object.assign({}, this.state);
copyState.form[name] = value;
this.setState(copyState);
}
This is an example of a functional form field:
<input value={this.state.form.username}
onChange={this.handleChange}
name="username"
type="text"
className="form-control"
/>
This does not work:
<input value={this.state.form.address.street}
onChange={this.handleChange}
name="address.street"
type="text"
className="form-control"
/>
The handleChange method works perfectly on the items: name, username, email, and phone, BUT in the attributes belonging to the address not.
How to solve this?
Thank you in advance. :)