Skip to content
Advertisement

Require non-static image in React Native

I have a special folder with images in my React Native application. Path to these pictures is stored in the special object that is passed as prop to the Card component. So, I can’t use require, because it uses only static path string. How can I use load these images from my props? There is my try:

JavaScript

Advertisement

Answer

As your images are local better create a json object by requiring the images like below

JavaScript

And you can set the url like below

JavaScript
Advertisement