How to use variables inside require()?

I’m having a problem here and I don’t know if it’s possible to do this, I’m pulling data as parameters of my route:

onPress={() =>
  navigation.navigate('product', {
    pathToImage: "../../images/airdots_category.jpg",

Then, I get them on my other page.

const pathToImage = route.params.pathToImage;

Now, I want to pass the pathToImage into the require():

<Image source={pathToImage} />

But it does not accept, since the path comes correctly, I find it strange because I just put the path inside a variable.

If you have another way of doing it … please!

4 thoughts on “How to use variables inside require()?”

Leave a Comment