what I'm trying to do is import all the images from a folder in React, here is my code:
const images = importAll(require.context('../assets/image/slider', false, /\.(png|jpe?g|svg)$/));
const importAll= (r) => {
let images = {};
r.keys().map((item, index) => { images[item.replace('./', '')] = r(item); });
return images;
}
My problem is that I need that the path is a variable because I need to set it dynamically.
I know that require.context params need to be literal but this feature is really important for my code and I can't figure out how to do it in a different way, because all the guides that I found do this thing with require.context.
Hope you can help, thanks!