This works:
handleOnChange(e) {
this.setState({[e.target.id]: e.target.value});
}
e.target.id
is wrapped in brackets ([ ]
), while e.target.value
is not.
I could write e.target.value
in brackets too and it would work, but if I remove the brackets from e.target.id
my code will not work. Why?
I did some research and believe this is because Computed Property Names (I am not sure though), but then the question arises, why does the property of e.target.id
needs to be computed while e.target.value
does not? Both of them are simply values I would think.