React 引用数组

React array of refs

我在 Whosebug 上阅读了 post

我们可以使用类似以下代码的方式将 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 }}/>

但是当我尝试时,它 returns 这个错误:

Uncaught TypeError: Cannot set property '0' of undefined

它不起作用,我是不是漏掉了什么?

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

constructor(){
  super()

  this.Progress = []
}

进度数组未初始化,请在构造函数中对其进行初始化..