• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

256
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error