The state of this form consists of three levels: A > B > C
A: [
{
name: "foo",
...
B: [
{
name: "bar",
...
C:[
{
name: "baz",
...
},
{
name: "bat":,
...
}
]
},
]
},
...
]
Basically, there needs to be an input field for each name attribute in three resources that are children of each other.
<div className="subvariation-tree">
{
this.state.A.map( (a, aIdx) =>
<div key={aIdx}>
<input type="text"
value={this.state.A[aIdx].name}
onChange={this.handleInputChange} />
{
a.B.map( (b, bIdx) =>
<div key={bIdx}>
<input type="text"
value={this.state.A[aIdx].B[bIdx].name}
onChange={this.handleInputChange} />
{
b.C.map( (c, cIdx) =>
<div key={cIdx} >
<input type="text"
value={this.state.A[aIdx].B[bIdx].C[cIdx]}
onChange={this.handleInputChange} />
</div>
)
}
</div>
</div>
)
}
</div>
</div>
)
}
</div>
Problem is, I guess it seems obvious but I'm not able to access aIdx for example within the loop for the C attribute.
Is there any way around this? Is this a ridiculous design? A ridiculous use case for React? I am struggling pretty badly with this idea. I think I could manage it in vanilla JavaScript but I am trying to learn React.
this.state.A[aIdx].B[bIdx].namethe same asb.name? You are the same iteration in your A and B at that point. (same fora.nameandc.name).aIdxin theCloop. Are you sure the problem is not the missing.nameat the end ?