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

142
Views
Change the color of a card while mapping through an array based on it's value in react?

I want to change the color of the card based on the value of the current slot which is an object in an array. So when I am mapping through a card I want to change the backgroundColor of the card based on the value. How should I do that? My current approach doesn't seem to work.

slots.map(slot => 
          <Card key ={slot._id} style={{backgroundColor:slot.OccupiedStatus?'black':'teal'}}>
            
            <Typography>{slot.category}</Typography>
          </Card>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since The Card is a React Component, in your case the style is not considered an attribute instead it is a prop that will be passed on to the Card component.

You can catch that style prop in your Card Component and use it.

const Card = (style, ...otherProps) => {
    return <div style={style} >hello</div>
}
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!