Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

360
Views
Alternative to Require Context where I can use variable

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!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!