React数组refs

Eli*_*ali 10 arrays refs reactjs

我已阅读有关refs的 Stackoverflow 问题的帖子

我们可以使用类似下面的代码将refs数组分配给不同的输入,如下所示:

<Progressbar completed={25} id="Progress1" ref={(input) => {this.Progress[0] = input }}/>

<Progressbar completed={50} id="Progress2" ref={(input) => {this.Progress[1] = input }}/>

<Progressbar completed={75} id="Progress3" ref={(input) => {this.Progress[2] = input }}/>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试它时,它会返回此错误:

Uncaught TypeError: Cannot set property '0' of undefined
Run Code Online (Sandbox Code Playgroud)

它不起作用,我错过了什么吗?

CD.*_*D.. 9

在构造函数中创建数组,如:

constructor(){
  super()

  this.Progress = []
}
Run Code Online (Sandbox Code Playgroud)