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> ); } }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b4487f-2c716.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b4487f-2c716.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?