Im make navigation on ReactJS, without plugins. And I want to create an array of main components. This is possible?
CoffeeScript:
Root = React.createClass
render: ->
self = this
<header>
<nav>
<ul>
{this.props.components.map((comp, i) ->
<li onClick={self.change.bind(self, i)}>{comp.name}</li>
)}
</ul>
</nav>
{this.props.components[this.state.active].component}
</header>
change: (i) ->
this.setState({active: i})
getInitialState: ->
active: 0
RootComponents = [
{name: "main", component: React.createClass
render: ->
<div>its main</div>
},
{name: "conf", component: React.createClass
render: ->
<div>its conf</div>}
]
React.render(
<Root components=RootComponents />,
document.getElementById("main")
);
This code returns items (main and conf) but not the component.
AGREED Edit: {this.props.components[this.state.active].component} To: {React.createElement(this.props.components[this.state.active].component, null)}