I have a small react page that should compile and display html string.
the html in the string written in react-foundation
The page looks like this :
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Link, Button, Colors } from 'react-foundation';
require('./foundation.css')
var htmlFromApi = '<div className="button-basics-example"><Button color={Colors.SUCCESS}>Save</Button><Button color={Colors.ALERT}>Delete</Button></div>';
var App = ({ html }) => { return <div>{html}</div> }
ReactDOM.render(
<App html={htmlFromApi}/>,
document.getElementById('react')
);
The Result of the above code is just a string, I am wondering if there is a way to convert the html string to react element
something like this :
var reactElement= toReactElement(htmlFromApi);
//the result is <div className="button-basics-example"><Button color={Colors.SUCCESS}>Save</Button><Button color={Colors.ALERT}>Delete</Button></div>
PS I tried <div className="content" dangerouslySetInnerHTML={{ __html: htmlFromApi }}></div>
and didn't work
Thanks in advance
Edit: the code is here
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…