Lets say I have ref variable that contains a list of divs:
const refDivs = useRef()
This ref has the format { current = [divC1,divC2,divC3,divC1,divC2,divC4]} and is filled using :
<c>
<c1 parentRef={refDivs}/>
<c2 parentRef={refDivs}/>
<c3 parentRef={refDivs}/>
<c/>
<c>
<c1 parentRef={refDivs}/>
<c2 parentRef={refDivs}/>
<c4 parentRef={refDivs} />
<c/>
I need to re-render the ref variable content in somewhere else -after doing some extra calculations- but the order is altered (e.g. { current = [divC4,divC2,divC3,divC1,divC1,divC2]} - sometimes its different) . I believe this is because rendering is async (right?). So, what would be the best way to ensure the order of this new renders keep the same order as the original one?
<div>{refDivs.current.map(d=>d)}</div>
I tried using like an index prop in the ref object , and order the items before re-rendering again, but its difficult to keep track of the hundreds of components I have (c4,c5, ... c100)
So basically what I want to see is the following :
<c1 />
<c2 />
<c3 />
<c1 />
<c2 />
<c4 />