Skip to content
Advertisement

Why my array resets itself when I leave my function?

I come here after two whole days without success. I want to increment my array with the pictures selected by the User, for return to my database a list of uri. But when the user choosed the first picture and re-open the android navigator for take a new picture, I saw the array doesn’t increment. It takes the first value, and when I leave the selectImage() method it is back to empty.

Here is my main function :

EDIT :

JavaScript

I tried with promises, changing my function in async, with a SetTimeOut but I guess the probleme is not with the Asynchronous. Someone for help ? Thanks a lot.

Advertisement

Answer

Use useState for your array to keep state even if you leave the screen:

JavaScript

And in your function instead of array.push(source) you use it like that:

JavaScript

And this should keep your result as I think the problem comes from the array and not the asynchronous function.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement