@samitouri / QOS-React-2 / commits / bf4bd19101

[docs] Use id for TodoApp example

Tay Yang Shun committed Nov 22, 2015 at 11:54 UTC bf4bd191015a4f8994fa138bc95fec6fdd012e6b
1 file changed +3 -3
docs/_js/examples/todo.js
+3 -3
@@ -1,8 +1,8 @@
1 var TODO_COMPONENT = `
2 var TodoList = React.createClass({
3 render: function() {
4 - var createItem = function(itemText, index) {
5 - return <li key={index + itemText}>{itemText}</li>;
4 + var createItem = function(item) {
5 + return <li key={item.id}>{item.text}</li>;
6 };
7 return <ul>{this.props.items.map(createItem)}</ul>;
8 }
@@ -16,7 +16,7 @@ var TodoApp = React.createClass({
16 },
17 handleSubmit: function(e) {
18 e.preventDefault();
19 - var nextItems = this.state.items.concat([this.state.text]);
19 + var nextItems = this.state.items.concat([{text: this.state.text, id: Date.now()}]);
20 var nextText = '';
21 this.setState({items: nextItems, text: nextText});
22 },