'How to add key-value to object in JS? [closed]
I found this expression, but I do not know where is it come from? Where is any documentation for it?
onChange={(
event: React.ChangeEvent<HTMLInputElement>
) => {
setFormData({ ...formData, [key]: event.target.value })
}}
Solution 1:[1]
You can just put any key name here i chose eventValue
setFormData({..formData, eventValue: event.target.value})
and then you should be able to access it like this
function setFormData(formDataObject){
// access it like this
formDataObject.eventValue
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 0szi |
