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

319
Views
React Js Inline style not working on loop condition

i am getting problem when doing loop in react JS. I want to make a different background for each item according to the data I have created. I tried to use the inline style to make it dynamic, but it doesn't work. Any suggestions or solutions regarding this?

        {
            main.map((item, index) => (
                <a key={index} href='#' className="col-12 main-item-img" style={{backgroundImage: `url(${item.bg})`, backgroundPosition: 'center', backgroundSize: 'cover'}}>
                    <h2>{item.name}</h2>
                    <img src={item.logo} className='item-img' alt={item.region} srcSet="" />
                    <p>{item.desc}</p>
                    <div className="overlay"></div>
                </a>
            ))
        }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solved! The problem is not in the loop but in the slick slider that I use. In the description I didn't explain that I was using the slick slider because I thought the problem was in the loop.

i just need to add before . The result is like this

    <Slider {...carouselSettings} style={{ width: '100%' }}>
        {
            main.map((item, index) => (
                <div> //add this element
                    <a key={index} href='#' className="col-12 main-item-img" style={{backgroundImage: `url(${item.bg})`, backgroundPosition: 'center', backgroundSize: 'cover'}}>
                        <h2>{item.name}</h2>
                        <img src={item.logo} className='item-img' alt={item.region} srcSet="" />
                        <p>{item.desc}</p>
                        <div className="overlay"></div>
                    </a>
                </div>
            ))
        }
    </Slider>
about 4 years ago · Juan Pablo Isaza Report
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!