// 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