In ReactJS I am trying to render a component from a string that I dynamically create. My render function looks like this:
render() {
var content = '<h1>Hello</h1>'
content += "<Link href={'http://www.google.com'} text={'Click Here'} />
content += '<h1>World</h1>';
return (
<div>
<div dangerouslySetInnerHTML={content} />
</div>
);
}
Except the component link is not being render and it is being printed as html. What am I doing wrong?
Linkdoesn't exist in HTML. You are telling React to treat interpret the string as HTML and that's exactly what it does.typeprop and based on the type prop the container component will render a different child component. I am unsure as to what the exact implementation is, so if you could elaborate on that that would help, but it sounds like you are taking an adverse approach to using components. I can guarantee there is a way to do this that is idiomatic in react.