React native useRef Hook wouldn't store an array

222 views Asked by At

Here's a simple code that doesn't work I really don't know why

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>

The result of the console log is 1 wathever I put in the array and wathever the way I initialyse the useRef. It works fine for not array variables and I didn't try it with objects.

Thanks for your help.

0

There are 0 answers