For context, I was reviewing Dynamically import images from a directory using webpack
When trying to use the importAll(i)
function,
It seems that my images object does not get populated and/or the images object is undefined.
Can anyone help as to where I am going wrong?
function importAll(i) {
let images = {};
i.keys().map((item, index) => {images[item.replace('./', '')] = i(item);
return images;
});
}
const images = importAll(require.context('../images', false, /\.png$/));
<img src={ images['chatLogo.png'] } alt="Chat Logo" width="300" height="250" />
My file directory:
I've got it in the components folder as I was trying to figure out if it was my filepath that was the issue.