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

297
Views
Sending in a prop object where some are dependant on a boolean value

I have the following component taking in the prop data.

<Button
    data={booleanValue && {
        d: 4,
        // another 8 key/values
    }}
/>

So data value only gets passed in if booleanValue is true.

But I also have another 3 more value which I wish to add inside this data which are meant to always show. So show irregardless of whether booleanValue is true or false.

Is there a way I could write this elegantly within the component above itself?

I could create the object separately like following which would work. But trying to see if I could achieve it without additional object creation.

One possible solution but don't want to create an object like this.

let obj = {
    a: 1,
    b: 2,
    c: 3,
};

if (booleanValue) {
    obj['d'] = 4;
    // more values being added same way.
}

<Button
    data={obj}
/>
about 4 years ago · Juan Pablo Isaza
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!