0

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.

achraf
  • 1
  • I just tested what you're doing and mine logged the array. What you're doing should work. Are you doing anything else with the ref or ref.current? – Sean W May 07 '21 at 03:36
  • Thank you for your test. I think it was a bug in visual studio cache or something because I did some cache delete and other things. I didn't touch my code and then magically it started working. I want to mark your answer as a the right one and I don't know how. There is only a flag in the left part. I'm new to stackoverflow. – achraf May 08 '21 at 16:07
  • Thanks, but you should delete the question as there wasn't really any issue that would be helpful to others. – Sean W May 09 '21 at 03:16

0 Answers0