最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to load an image dynamically in React Native Expo (2400+ Images) - Stack Overflow

programmeradmin1浏览0评论

I have the problem that I have about 2400 images in my assets folder. The following structure:

/assets/images/items/<first 2 letters of imgname>/imagename.png

Of course, I don't need all of them all the time, so I want to dynamically load the images I need. I find out which ones need to be loaded via a fetch API, on average between 10-40.

Now I know that this can't be achieved with require('/assets/images/items/'+getImgName());.

But does it make sense to generate an index.js file with all the images, like this:

const imagesList = {
    item1: require('./src/assets/item1.png'),
    item2: require('./src/assets/item2.png)
}

which then contains all 2400+ images?

Or is there a better way? Besides, is it even a good idea to have such a large array?

I originally loaded it via a CDN, but since it's only 30MB in total, I thought it made more sense to have it locally.

发布评论

评论列表(0)

  1. 暂无评论