Basically, every time I select an element (in this case a photo), the details of that element are inserted into the array called "photoArray". When the length of the photoArray is greater than or equal to 2 set the "isComparable" status to true. The display of a comparison button depends on the value of this state. That said, the problem lies in the fact that when I call the React setIsComparable method to set the state, this operation resets the photoArray from time to time, leaving it full of the data of the last selected image and not of all those selected, up to that moment, as it should be. The very strange thing is that if I avoid calling the setState everything works correctly. How can a setState cause an array to be reset?
For convenience, I am attaching a Snack that shows the exact functioning of my code and the problem I have described to you.
Ps .: unfortunately from the Snack in the "web" version the images are not seen, but from the "Android" or "iOS" device the simulation is perfectly congruent with my app
EXPO SNACK: https://snack.expo.io/@sido95/array-push-not-work