I'm storing text content in a JSON file and outputting it in JSX. (In my case, I'm using Gatsby and querying the JSON using GraphQL.)
For example, the following JSON...
// example.json
[
{ "phrase": "Hello, world!" },
{ "phraseWithHTML": "<em>Hello</em>, <a href=\"https://example.com\">world!</a>" }
]
...is output in the following JSX:
// ...
<p>{example.phrase}</p>
<p>{example.phraseWithHtml}</p>
// ...
In both cases, the strings are output as plain text (i.e. phraseWithHtml
is displayed as a string rather than the intended: Hello world.
Is there a way to output example.phraseWithHTML
as HTML instead? Do I need to store it differently in the JSON file? Is there a way to transform it in the JSX?