Skip to content

Instantly share code, notes, and snippets.

@lukehedger
Last active October 7, 2018 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukehedger/5a1478d00f5b8d036c64192de4417240 to your computer and use it in GitHub Desktop.
Save lukehedger/5a1478d00f5b8d036c64192de4417240 to your computer and use it in GitHub Desktop.
Render HTML elements defined in JSON to JSX
import React from 'react';
const Component = (props, context) => {
const { elements } = this.props;
return (
<div>
{elements.map( (element, i) => {
const { tag, content } = element;
return (
<div key={i}>
{React.DOM[tag](null, content)}
</div>
);
} )}
</div>
);
};
export default Component;
"elements": [
{
"tag": "p",
"content": "Some content goes here"
},
{
"tag": "div",
"content": "Some content goes here too"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment