I have a component in reactjs with all image imported as
import client01 from '../../assets/images/site/client-01.png';
import client02 from '../../assets/images/site/client-02.png';
import client03 from '../../assets/images/site/client-03.png';
import client04 from '../../assets/images/site/client-04.jpg';
import client05 from '../../assets/images/site/client-05.jpg';
import client06 from '../../assets/images/site/client-06.jpg';
and used in code as
<img src={client05} alt="client_5" />
My question is if I'm getting these values from an api, then how should I load the images. for example,
{
"web-data": {
"Asset": {
"client01": "../../assets/images/site/client-01.png",
"client02": "../../assets/images/site/client-02.png",
"client03": "../../assets/images/site/client-03.png",
"client04": "../../assets/images/site/client-04.png",
"client05": "../../assets/images/site/client-05.png"
}
}
}
and i got these values and stored it in a local state, How to import these images in my reactjs component?
web-data.asset.client05it will give the same output. As long as the field has a valid url it is ok. It doesn't matter it is variable or hard code string