yan
yan

Reputation: 1

reactjs load images from their local path

I am trying to load an array of images, through their path which i am taking from a rest api but i am taking the error:

Module not found: Can't resolve 'tempString' in 'C:\Users\User\Desktop\React\yiannis\touch\touch\touch\src\pages\en'

and the code is:

{photo.map(image=>( 
                              //tempString = image.replace("../","../../"),
                              this.setState({tempString : image.replace("../","../../")}),   
                               currentImage = require('tempString')
                              //Images.push(currentImage)  
                        ))}

Any ideas what am i doing wrong?

Upvotes: 0

Views: 51

Answers (1)

Root
Root

Reputation: 2361

I think you miss const,you haven't define tempString but to pass date to it.

const tempString = image.replace("../","../../")

And here, what is 'tempString',I think there are some problems here.

require('tempString')

Edit 2:

const Image = []
{photo.map((image) => (
   Image.push(image.replace("../","../../"))
)}

Upvotes: 1

Related Questions