1

I have to develop a mobile application that will have hundred of "cards" with an image. All images will be locally stored. I have seen that, in React Native, images are loaded using require and a constant file path string as parameter. I can create an array with all images user could need, but I don't know how memory is handled in this situations. Is there a better approach to solve that?

marcm
  • 171
  • 9
  • See [here](https://stackoverflow.com/questions/30854232/react-native-image-require-module-using-dynamic-names). You can't load bundled images via an array as the `require` statements are pre-compiled when the bundler runs; each image must be present at the path supplied. In terms of performance, will hundreds of images be on screen at once? This might be an issue on low-end devices, but if not, you should be fine referring to them all via `require`. – G0dsquad Jun 12 '17 at 12:34
  • I said array and I meant object. The idea is to load a JSON with a collection of items to display individually in "cards". Each item has an associated image. I see that i cannot load this imatge dynamically, but my idea was to do an initial load inside the images pool object like `images["key"]=require("literal/path/to/image");` I will never show more than one image at the same time. What I was not sure of was whether it was ok in terms of memory usage to "require" some hundreds of images that will probably won't be needed. Thank you. – marcm Jun 12 '17 at 19:26

1 Answers1

0

Haven't tried it yet, but react-native-fast-image might be what you are looking for!

Alexandre Rivest
  • 694
  • 5
  • 14
  • Thank you, but I don't think I made myself clear enough. I do not have to display all images at once. My concern was about requiring hundreds of locally stored images that will probably not be displayed. – marcm Jun 13 '17 at 08:43