I have some json with data and one of param is path to my local folder with images:
// data.json
[
{
"id": 1,
"image": "assets/somepic.png"
},
{
"id": 2,
"image": "assets/anotherpic.png"
}
// similar data goes there
]
Then I import those data into my component
import data from "data.json"
and I want to map thru this data:
render() {
return (
data.map((item) => (
// Ofc it won't work if I just put {item.image} in src,
// because we need to import image before use it
// that's why I'm trying to use require
<img src={require(item.image)} />
))
)
}
But it won't work. How can I use images, which local patch is specified in json data for create-react-app?
Please, note: app should NOT be ejected.