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

193
Views
How can we pass a color as a prop?

I have a component which has the color white if it is active and black if it is inactive. How can a pass the color black as a prop?

My code right now (it does nothing):

export function Card (props) {
  return <div {...props} className={styles.gray} />
}

I want to use this component (called Card) in a ternary operator to show if the component is active or not.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Assuming that you are setting the active state outside of the card, here's the simple ternary pattern.

If active is defined outside of the card:

function Card({ isActive, ...props }) {
  return (
    <div
      className={`${styles.gray} ${isActive ? styles.active : null}`}
      {...props}
    />
  )
}

Using a helper like clsx, it would look like:

<div className={
  clsx(
    styles.gray,
    isActive ? styles.active : null,
  )
} />
about 4 years ago · Juan Pablo Isaza Report

0

Is styles the name of your css style sheet and gray the selector?

There are a bunch of different ways to create this behavior, but an easy one if you have a props object with color as a prop, you can do: <div style={{ color: props.color }}

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!