Can’t figure out what is going on here (using an image because it’s clearer to explain).
On highlighted line #114, movesAry
is undefined. Initially, all breakpoints (outside of the one highlighted, which is not executed initially) show it as an empty array. However, when selecteDb
changes and useEffect()
is triggered for the first time, the movesAry
value has become undefined. Note that no call to setMovesAry()
has been made yet. Subsequent breakpoints now also show that movesAry
is undefined.
2
Answers
I wound up breaking down the component into smaller ones, ending up with a
MoveRows
component that gets themovesAry
state via props. So now in myuseEffect
function I am able tosetMovesAry
without it blowing away themovesAry
state.I also got rid of the
pojos
ref by merging it into theselectedDb
structure. Everything seems to work now, so I'll mark this as the answer.What could be happening is that, on line 120, arrSeg gets assigned an object such that
arrSeg.value
is undefined. Then you callsetMovesAry(arrSeg.value)
, which causes movesAry to be undefined