ComponentDidMount in react cannot get real dom

after setting ref in render, the real node cannot be obtained in componentDidMount. The specific code is as follows.

export default class Content extends Component{
  componentDidMount() {
    console.log(this.p);
  }

  render() {
    const arr = [{content:""},{content:""},{content:""}];
    
    const domP = arr.map((item,i) => {
      return <p ref={(dom) => this.p = dom} key={i}>{item.content}

}); retuen ( <div> {domP} </div> ); } }
Mar.22,2021

Let's start with the reason: the map method traverses the array and causes the this.p to be constantly reassigned, so what you get in componentDidMount is always the dom node created by the last traversal of the array.
provide a solution:

export default class Content extends Component{
  componentDidMount() {
    console.log(this.p0);
    console.log(this.p1);
    console.log(this.p2);
  }

  render() {
    const arr = [{content:''},{content:''},{content:''}];
    
    const domP = arr.map((item,i) => {
      return <p ref={(dom) => this['p' + i] = dom} key={i}>{item.content}

}); retuen ( <div> {domP} </div> ); } }
Menu