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

135
Views
Conditionally pick a prop to use
const Component = ({

    const someBoolean 

    return (
          <Component
             prop1
             prop2

I want to use prop1 ONLY when someBoolean is true, otherwise prop2 should be used. What is the best way to do this ?

So say someBoolean is true I would have

const Component = ({

    const someBoolean 

    return (
          <Component
             prop1

Otherwise I would have

const Component = ({

    const someBoolean 

    return (
          <Component
             prop2
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Best way to do this is with ternary operators. I'm new to React and this I believe is how you can implement conditional rendering

const Component = ({

    const someBoolean 

    return (someboolean ? <Component prop1> : <Component prop2>)
}) 
about 4 years ago · Juan Pablo Isaza Report

0

You can use spread operator.

const Component = ({
    const someBoolean;
    const finalProp = someBoolean ? prop1 : prop2;   

    return (
          <Component {...finalProp} />
    )
})
about 4 years ago · Juan Pablo Isaza Report

0

const Component = ({

    const prop = someBoolean ? prop1 : prop2 

    return (
          <Component {...prop} />
})
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!