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!

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

  1. I seriously love your site.. Very nice colors & theme.

    Did you build this amazing site yourself? Please reply back as I’m
    trying to create my very own site and would like to learn where you got this from
    or just what the theme is named. Cheers!

    Reply
  2. I’m not sure the place you are getting your info, but good
    topic. I must spend a while finding out more or working out more.

    Thanks for great info I was looking for this info for my mission.

    Reply
  3. Do you have a spam problem on this website; I also am a blogger, and I was wanting to know your situation; many of us have created some
    nice methods and we are looking to swap methods with others, please shoot me an e-mail
    if interested.

    Reply
  4. Oh my goodness! Awesome article dude! Thank you, However
    I am encountering problems with your RSS. I don’t understand
    why I can’t join it. Is there anyone else getting identical RSS problems?
    Anyone that knows the solution can you kindly respond?
    Thanx!!

    Reply
  5. Fantastic blog! Do you have any hints for aspiring writers?
    I’m planning to start my own website soon but I’m a little lost on everything.
    Would you advise starting with a free platform like WordPress or
    go for a paid option? There are so many choices out there that
    I’m totally overwhelmed .. Any tips? Bless you!

    Reply
  6. I have been surfing online more than 4 hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my view, if all web owners
    and bloggers made good content as you did, the net will be much
    more useful than ever before. scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery

    Reply