https://stackoverflow.com/questions/36651583/dynamically-add-child-components-in-react
var App = require('./App.js');
var SampleComponent = require('./SampleComponent.js');
ReactDOM.render(
<App>
<SampleComponent name="SomeName"/>
<App>,
document.body
);
var App = React.createClass({
render: function() {
return (
<div>
<h1>App main component! </h1>
{
this.props.children
}
</div>
);
}
});
var App = React.createClass({
getInitialState: function(){
return [
{id:1,name:"Some Name"}
]
},
addChild: function() {
// State change will cause component re-render
this.setState(this.state.concat([
{id:2,name:"Another Name"}
]))
}
render: function() {
return (
<div>
<h1>App main component! </h1>
<button onClick={this.addChild}>Add component</button>
{
this.state.map((item) => (
<SampleComponent key={item.id} name={item.name}/>
))
}
</div>
);
}
});
dynamically-add-child-components-in-react
https://gist.github.com/xyzdata/5acc4a357722e9e2636009fbd6846338#gistcomment-2133571
how to dynamically generate nested li list using js
https://gist.github.com/xyzdata/50d9af7fe5749fe199146e4e5e2f3f1e#gistcomment-2133425