• Home
  • How to bold specific text in a string in a React JS App?

How to bold specific text in a string in a React JS App?

To bold specific text in a string in a React JS app, you can use the style attribute and the fontWeight property. Here’s an example:

const string = "This is some text, and I want to bold the word 'bold'"

return <p>{string.replace("bold", <span style={{fontWeight: "bold"}}>bold</span>)}</p>

This will replace the word “bold” in the string with the word “bold” wrapped in a span element with a fontWeight of “bold”. The resulting text will be “This is some text, and I want to <b>bold</b> the word ‘bold'”