3

My problem specifically is that I would like to be able to create dynamic templates, depending on the type of item contained in a certain record. I would like to store these components as strings in the database and render them dynamically as the items are loaded. The templates would need to be able to handle dynamic react variables. They are not just html strings as in some of the other examples on stackoverflow.

How might one go about doing this? Is it even possible?

meesterguyperson
  • 1,726
  • 1
  • 20
  • 31
  • possible duplicate of [How to render a react element using an html string?](http://stackoverflow.com/questions/29706828/how-to-render-a-react-element-using-an-html-string) – Jakemmarsh Jul 24 '15 at 20:24
  • or consider ["Render a react component based on its name"](http://stackoverflow.com/questions/29195204/render-a-react-component-based-on-its-name) or ["Dynamically rendering a react component"](http://stackoverflow.com/questions/26518629/dynamically-rendering-a-react-component) – 00500005 Jan 15 '16 at 05:39

1 Answers1

1

You can use dangerouslySetInnerHTML, documented here.

function createMarkup() { return {__html: 'First · Second'}; };
<div dangerouslySetInnerHTML={createMarkup()} />

This is also discussed here.

Community
  • 1
  • 1
Jakemmarsh
  • 4,601
  • 12
  • 43
  • 70