When dealing with an object, we can use bracket notation, so:
obj["firstName"]
is the same thing as:
obj.firstName
Here is a sample input field:
<input type="text" name="firstName">
When we enter the event into the event handler, it will have the name of firstName, or whatever we choose for the name property in the input. Because we are using bracket notation, it will look for that property in the object, state. Does that make sense?
Here is an article that explains it in more detail.
oh, ok, I think I get it. So [name] will work here as variable that searches in property of object and while name: would be treated as a title of parameter. Is it also a shorthand i suppoust ? How it knows in which object looking for. I guess its about setState implementation.
Yes, if I put ‘firstName’ as the name of the input element, then event.target.name will be ‘firstName’ and it will be looking for a property in the state called ‘firstName’.
If you are still wobbly on this you can read this short article on the matter, this technique is called computed property names and it’s one of the new features of ES6.