Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render a template string as HTML?

Let's say I have a simple template string :

const foo = `<div>foo</div>`;

How do I go about rendering this template string as HTML ? It renders it as plain text if I do the following :

return({ foo });

Output:

<div>foo</div>

Expected output:

foo
like image 692
Chuck Avatar asked Mar 07 '23 14:03

Chuck


1 Answers

I think what you try to do is

const foo = `<div>foo</div>`;
<div dangerouslySetInnerHTML={{ __html: foo }}></div>

Related question.

React documentation.

like image 188
Tomasz Mularczyk Avatar answered Mar 25 '23 11:03

Tomasz Mularczyk