我在 Stackoverflow 上读过一篇关于 refs 的问题
我们可以使用类似下面的代码将一个 ref 数组分配给不同的输入,如下所示:
<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 }}/>
但是当我尝试它时,它会返回此错误:
Uncaught TypeError: Cannot set property '0' of undefined
它不起作用,我错过了什么吗?