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

288
Views
Why bolding a specific characters of a string does not render <b> element in React js?

I wanna bold a specific part of a string in my react js app but the result is not true; This is my code and its returned:

data?.map((item) => (<li key={item.id}>{item.title.replace(new RegExp(value, 'g'), `<b>${value}</b>`)}</li>)) // rendered value: app<b>l</b>e
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because you're returning a string, not a react element. That is to say, There's an important difference between app<b>l</b>e (an array of react elements) and 'app<b>l</b>e' (a string).

data?.map((item) => (
      <li key={item.id}>
      {
        // spread to convert string to array
        [...item.title].map((letter) =>
          // if the letter matches, wrap in a <b/> tag
          letter === value ? <b>{letter}</b> : letter)
      }
      </li>
    ))

https://codesandbox.io/s/pedantic-tree-r4egc?file=/src/App.js

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!