动态引用使用ref回调方法

Jan*_*Jan 6 react-native

您如何设置动态参考?我得到一个错误cannot set property of 'test' undefined,如果我使用

<View ref={(ref) => this.someRef['test'] = ref;}/>
Run Code Online (Sandbox Code Playgroud)

vin*_*ayr 9

在为其this.someRef分配属性之前,必须设置为数组或对象.

this.someRef = [];
or
this.someRef = {};
Run Code Online (Sandbox Code Playgroud)