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

107
Views
Applying style to value in an object in React JS

I have the following map inside my React js file which i am mapping to a select dropdown.

 const options = response.map(k => ({
          value: k.id,
          label: k.description ? `${k.name} - ${k.description}` : k.name,
        }));

I need to either add a div or apply inline style only to ${k.name} value. for example i want ${k.name} to be bold and apply higher font-size value. what is the best way to do this?

Expected Output : https://nimb.ws/sb70xu

Thanks in advance

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

0

Presuming you already have an Option component, you should be able to create a component that accepts the items from the given response as props


const Options: React.FC<Data> = ({ id, name, description }) => (
  <Option value={id}>
    <span className="yourClassHere">{name}</span>
    {description && (
      <span>- {description}</span>
    )}
  </Option>
)

const options = response.map(option => <Options {...option} />);

TS Playground

MUI exmaple

about 4 years ago · Juan Pablo Isaza Report

0

const options = response.map(k => ({
          value: k.id,
          label: k.description ? `${<span style={{fontWeight: "bold"}}>k.name</span>} - ${k.description}` : k.name,
        }));
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!