Skip to content

Instantly share code, notes, and snippets.

@martellaj
Created July 28, 2015 20:12
Show Gist options
  • Save martellaj/f6715f94de63d814b19e to your computer and use it in GitHub Desktop.
Save martellaj/f6715f94de63d814b19e to your computer and use it in GitHub Desktop.
Binding Firebase items to List as an array instead of object
var React = require('react');
module.exports = React.createClass({
renderList: function() {
if (this.props.items && Object.keys(this.props.items).length === 0) {
return <h4>
Add a todo to get started.
</h4>
}
else {
// Make an empty array (React can handle arrays while rendering JSX).
var children = [];
// Iterate over items and extract the text from each.
for (var i in this.props.items) {
children.push(
<li>
{this.props.items[i].text}
</li>
);
}
return children;
}
},
render: function() {
return <ul>
{this.renderList()}
</ul>
}
});
@martellaj
Copy link
Author

Don't forget to change this.bindAsObject to this.bindAsArray in app.jsx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment