0

这是一个不起作用的简单代码我真的不知道为什么

const myArray = useRef(null) // or const myArray = useRef([]) or const myArray = useRef(new Array())

...Inside the functional component

<TouchableWithoutFeedBack onPress={()=>{
 myArray.current = [5, 6];
 console.log(myArray.current);
}}> 
  <View>
    <Text>some text<Text>
  </View>
</TouchableWithoutFeedBack>

控制台日志的结果是 1 无论我放入数组还是初始化 useRef 的方式。它适用于非数组变量,我没有尝试使用对象。

谢谢你的帮助。

4

0 回答 0