Next.js Discord

Discord Forum

Dynamic image import

Unanswered
Lithuanian Hound posted this in #help-forum
Open in Discord
Lithuanian HoundOP
I know this sounds counter intuitive, but I hope folks can understand why I'm asking.

I have a bunch of images that I'd like to statically load, to use the next Image component. But which image to load will depend on what the page in question needs. For example, the total image list is something like ["a.jpg","b.jpg","c.jpg","d.jpg","e.jpg","f.jpg","g.jpg","h.jpg","i.jpg","j.jpg"]. But page 1 may only need a, d, f, where as page 2 may need c, d, g, h.

Is there a way to use an array to first import image with the import image_name from '@/image/path?

0 Replies