I want to build up a ul list from li elements, but the li elements will come from different sources, so I can't do it in one statement. It appears that JSX can't handle a set of child elements, this gives me a syntax error:
var items = <li>S</li>
<li>S</li>
<li>S</li>;
Ideally I want to do something like:
var items1 = <li>S</li>
<li>S</li>
<li>S</li>;
var items2 = <li>S</li>
<li>S</li>
<li>S</li>;
var list = <ul>{items1}{items2}</ul>;
Is there another way to achieve this?
children should either be a ReactElement or an array of ReactElement, but not components. To get the DOM nodes of the children elements, you need to clone them and assign them a new ref. You can then access the child components via this. refs[childIdx] , and retrieve their DOM nodes via ReactDOM.
We can build a loop and add a JSX element to an array using the for a loop. elements.
JSX desugars very straightforwardly to Javascript syntax so you can mix it freely.
/** @jsx React.DOM */
var items1 = [ <li>S</li>, var items1 = [ React.DOM.li({}, "S"),
<li>S</li>, React.DOM.li({}, "S"),
<li>S</li> ]; React.DOM.li({}, "S") ];
var items2 = [ <li>S</li>, var items2 = [ React.DOM.li({}, "S"),
<li>S</li>, React.DOM.li({}, "S"),
<li>S</li> ]; React.DOM.li({}, "S") ];
var list = <ul>{items1+items2}</ul>; var list = React.DOM.ul({}, items1+items2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With