0

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!

AndresdoSantos
  • 49
  • 1
  • 1
  • 5
  • Check https://stackoverflow.com/a/62192731/2873538 – Ajeet Shah Feb 18 '21 at 03:32
  • Does this answer your question? [How do I dynamically import images in React?](https://stackoverflow.com/questions/62192049/how-do-i-dynamically-import-images-in-react) –  Feb 18 '21 at 04:37

1 Answers1

3

You can add require with the image path like this from where you passing your parmas.

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

const pathToImage = route.params.pathToImage;

<Image source={pathToImage} />
Hamas Hassan
  • 830
  • 6
  • 15