I am looking for smart method to handle input change in React
I have input
<input type="text" name="name" onChange={(e) => this.handleInputChange(e)} />
And function to handle input change
handleInputChange(event) {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({
[name]: value
});
}
But I need to change sometimes not property of state, but property of state object (or property of property of state object...) for example:
const entity = this.state.entity;
entity[name] = value;
this.setState({
entity: entity
)}
Some ideas for multilevel?
name="location.lat"for example, and write some code to iterate through the levels of the .notation or use a library