3

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.

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
Xen_mar
  • 8,330
  • 11
  • 51
  • 74

1 Answers1

7

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)

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230