vimwiki

React useRef

Using useRef to access element created by a loop

// initialize the ref with an empty object
const itemEls = useRef({});

// create the items and add them to the ref object
{items.map((item, index)) => (
 <p key={item} ref={(element) => itemEls.current[index] = element}>{item}</p>
));

More info