Reactjs onChange event returns element not an object
I have this code.
<Grid item md={4} sm={2} xs={12}>
<TextField
label="Qty"
name="qty"
id="qty"
variant="filled"
type="number"
fullWidth
onChange={itemChange}
value={item.qty}
></TextField>
</Grid>
<Grid item md={4} sm={2} xs={12}>
<TextField
label="Unit price"
name="unitPrice"
variant="filled"
type="number"
fullWidth
onChange={itemChange}
value={item.unitPrice}
></TextField>
</Grid>
In my itemChange
method, I console log the e.target
const itemChange = async (e) => {
console.log("e", e.target);
setItem({ ...item, [e.target.name]: [e.target.value] });
};
I got this
But I expect to get an object. So then I can use target.value
or target.name
.
Why could this happen?
from Recent Questions - Stack Overflow https://ift.tt/2S9ESci
https://ift.tt/3mXEI5P
Comments
Post a Comment