I use this in ruby on rails with react-rails.
In my app ,I want to use ajax to get a html response:
<%= react_component('Post') %>
Post Component:
var Component = React.createClass({
render:function(){
return <div>Article</div>;
}
})
and attach it to App Component:
var App = React.createClass({
getInitialState:function(){
return {html:''};
},
componentDidMount:function(){
var that = this;
$.get('/home/component').done(function(data){
that.setState({html:data});
});
},
getHtml:function(){
return { __html:this.state.html};
},
render: function() {
return <div dangerouslySetInnerHTML={this.getHtml()}></div>;
}
});
But after that it is fail, which show:
<div data-react-class="Post" data-react-props="{}"></div>
I already add post.js app.js to index.html. How can I mount this to DOM. Thank.....