I'm new to react Js and try to understand how to do composition on data I obtained from different sources, via ajax (as explained here: Reactjs - loadResourcesFromServer - combine two sources).
I have a Comment object and an Author object.
var Author = React.createClass({
...
render: function() {
return (
<div><a>{this.state.data.username}</a><img src="{this.state.data.picture}" /></div>
);
}
});
var Comment = React.createClass({
...
render: function() {
return (
<div><p>{this.state.title}</p></div>
);
}
});
Calling < Author /> and < Comment /> return 2 separate divs, but I want to display something like
<div>
<p>
<img src="{this.state.data.picture}" />
{this.state.title}, published by {this.state.data.username}
</p>
</div>
I tried to use a wrapper
<CommentWithAuthor>
<Author/>
<Comment/>
</CommentWithAuthor>
but can only access the props of the objects in this wrapper, not the objects themselves. I cannot use refs since I need a new renderer (React.js - access to component methods).
Any idea? Thanks!