How to format specific words in a sentence in react-intl

7.5k Views Asked by At

How to render nested elements in react-intl

What I'm trying to render:

<FormattedMessage>
    This is a <strong>House</strong>
</FormattedMessage>

This has been discussed here and there should be examples in the docs, but I can't find them.

1

There are 1 best solutions below

0
On

What you want is called Rich Text Formatting. Here is an example:

{
  "SENTENCE_WITH_BOLD_WORDS": "This is a <b>house</b>"
}
<FormattedMessage
  id="SENTENCE_WITH_BOLD_WORDS"
  values={{
    b: (chunks) => <strong style={{ color: "red" }}>{chunks}</strong>
  }}
/>

Live Demo

Edit 64122522/react-intl-how-to-add-a-number-in-a-message (forked)