I have my data in array format inside the object.
Here is the JSON data:
[
{
"id": "1",
"details": [
{ "id": "12wer1", "name": "ABC", "age": 15 },
{ "id": "78hbg5", "name": "FRE", "age": 21 }
]
},
{
"id": "2",
"details": [
{ "id": "po78u9", "name": "TER", "age": 18 },
{ "id": "dre87u", "name": "YUN", "age": 30 }
]
}
]
I want to change the name and age with respective of the "id". It should not get change for another "id". For Example: if i want to change name = "ABC" then it should not change for the Name="FRE". But couldn't able to do that.
Can anyone help me in writing proper onChange funtion for this and validation for text field?
Here is the sample code:
{this.state.Data.map((i) => (
<>
{i.details.map((y) => (
<Grid container justify="center" spacing={2}>
<Grid item xs={3}>
<TextField label="Name" variant="outlined" value={y.name} />
</Grid>
<Grid item xs={3}>
<TextField label="Age" variant="outlined" value={y.age} />
</Grid>
</Grid>
))}{" "}
</>
))}
</>