Expecting the below code to attach an unordered list and its child <"li" />
nodes to the document.body, it's OK with the <"ul" />
but without any children and with an error message in the console:
React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for composite components).
(React.js ver.0.13)
var ListView = React.createClass({
render: function() {
var items = this.props.data.map(function(item) {
return ItemDelegate({key:item.id, data:item.id});
}.bind(this));
return (React.createElement('ul', null, items));
}
});
var ItemDelegate = React.createFactory(ListViewChildren);
var ListViewChildren = React.createClass({
render: function(){
return (React.createElement('li', {key: this.props.key, data: this.props.data}));
}
});
var Wrapper = React.createClass({
render: function() {
return (React.createElement(ListView, {data: [/*some data*/]}));
}
});
React.render(React.createElement(Wrapper), document.body);
What type is it and where is it that the stated type has to be declared? I guess there's a total misunderstanding of the concept somewhere, but where?
The warning comes from
var ItemDelegate = React.createFactory(ListViewChildren);
ListViewChildren
is defined below so React cannot create the factory.
Just move the var ListViewChildren = ...
above and the warning will go away.
You also have an issue in the ListView
class: your items
should be children and not props:
// items as props (2nd arg): won't work, html elements don't have props :)
return (React.createElement('ul', items));
// items as children (3rd arg) should work better
return (React.createElement('ul', null, items));
Full code: http://jsfiddle.net/Lmb7t9pv/2/
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