我将从我的模板渲染中获取动态html内容,该内容由其他反应组件呈现.我如何将这个html字符串转换为React组件,以便我可以在我的渲染函数中使用该组件.请注意,我想保留用于差异的特定反应属性.
React.createClass( {
var self = this;
componentWillMountDown : function() {
//htmlString is essentially huge dynamic one in my actual case
var htmlString = "<div class='classDiv' react-id="0.1"><input type='text'/></div>";
self.setState({responseString : htmlString});
self.forceUpdate();
},
render: function() {
var Response = this.state.responseString;
//how would I return the react component as response?
return (<Response/>); //does not work. err is it shd be valid react component
}
});Run Code Online (Sandbox Code Playgroud)
我已经尝试将htmlString转换为HTMLDocument对象,并在willmount回调中递归创建React.createElement并设置react组件.但是,错误是类型toUpperCase未定义.