I have a JSON response with a load of data such as an image location.
Then when I try to load the image React cannot find it.
None of the answers of similar questions help because they all tell me to import the image but I need to load it on the cuff. Eg:
{Object.values(this.state.advertisements).map((advertisement, i) => {
...
<img width='80px' src={require(advertisement.image)} alt='house'/>
Then I get an error 'cannot find module'.
The path looks like this:
image:
./images/house.JPG,
requireis a directive to load a module such as JS files. Rarely is it used to include other formats such as images. How is your image data stored? As actual URLs to an external server or encoded data? If it's the former you can just usesrc={advertisement.image}assuming your data is well-defined.imgelements should have uniquekeyprops to help React with rendering.