I understand that you can't return multiple elements. But this limitation is causing me to not be able to solve this problem without help.
I am working with an HTML design from another that uses a 1 depth list to represent a 3 depth list. As a last resort I can change this.
An example of the HTML I am converting to React. The number of Devices, cards and remotes could all be different on every GET request.
<ul class='deviceList'>
<li>Device A`</li>
<li>Cards Connected in Device A</li>
<li>Card 1</li>
<li>Card 2</li>
<li>Remotes Connected to Device A</li>
<li>Remote 1</li>
<li>Device B</li>
<li>Cards Connected to Device B</li>
<li>Card 1</li>
<!-- ... could go on for more ...-->
</ul>
This is how I setup the React code that actually contains the <ul>:
var DeviceList = React.createClass({
render: function() {
var deviceList = this.props.devices.map(function (device) {
return [
<DeviceTitle title='{device.name}' />,
<ComponentTitle title='Cards' />,
<Cards cards={device.cards} />,
<ComponentTitle title='Remotes' />,
<Remotes remotes={device.remotes} />
];
});
return (
<ul className='deviceList'>
{deviceList}
</ul>
);
}
});
So the problem is the Card and Remote components need to return multiple list components. I tried having it return an array of list components but this did not work.
Here is what I have .. this is the part that fails.
var cards = React.createClass({
render: function() {
var cards = this.props.cards.map(function (card) {
return (
<li>{card.name}</li>
);
});
// illegal
return {{cards});
}
});
// Remote is a little different but same problem
Also.. to try to make this simpler I only showed a 3 depth list but really it is 4 depths. Each card and remote could have other components attached to them.
So as other questions here have shown. I can't do it this way. So what should I do?