I write the code below,
source={require(`../../assets/images/${post.image}`)}
in this {post.image} have dynamic values, its something like an array – img1.png,img2.png likewise
How to concatenate this path and values.
It’s working on react but it’s not working on react-native, How to solve that issue ?
2
Answers
In react native you can’t have dynamic resources with require. Check React Native docs for solution:
https://reactnative.dev/docs/images#static-image-resources
you can’t use variable in require. You can store your resource in an constant like
Or string constant directly
documentation link was provided in the answer by @role
in the documentation for images in assets folder
use the
asset:/
schemeif that does not work then create a dictionary of image components