First of all, I've found the solution here, which works great with a single array of elements. But my question is regarding the nested arrays of components. For example:
const { useRef, useState, useEffect } = React;
const arr1 = [A, B, C]
const arr2 = [1, 2, 3]
const App = () => {
const popoverRefs = useRef([]);
return (
<div>
{arr1.map((parentItem, index) => {
return(
<div>
A Parent Element {parentItem.label}
{arr2.map((childItem, index2) => {
return (
<div ref={????}>
A Child Element {childItem.label}
</div>
)
})}
</div>
)
})}
</div>
);
};
ReactDOM.render(
<App />,
document.getElementById("root")
);
In this example how can I use useRef
or createRef
to get the reference for each parent's child separately, so that I can use those references to anchor some other view for example a popover.