I have created a project with create-react-app and I have a folder called images inside the source. I want to loop inside the images folder and display them.
So far my code look like this:
import React, { Component } from 'react'
import images from './images/wd/'
const listOfImages = []
class Myloop extends Component {
importAll(r) {
return r.keys().map(r)
}
componentWillMount() {
listOfImages = this.importAll(require.context(images, false, /\.(png)$/))
}
render() {
return (
<>
<ul>
<li>
{listOfImages.map((images, index) => (
<img src={images} key={index} alt="info"></img>
))}
</li>
</ul>
</>
)
}
}
export default Myloop
After saving the file I have the following message on the terminal:
Module not found: Can't resolve './images/wd/' in '/mywebsite/src/components'
I'm not sure what is wrong, but any help will be great.