动态引用使用ref回调方法

时间:2017-03-10 16:35:49

标签: react-native

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

<View ref={(ref) => this.someRef['test'] = ref;}/>

1 个答案:

答案 0 :(得分:8)

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

this.someRef = [];
or
this.someRef = {};