Skip to content

Instantly share code, notes, and snippets.

@joshma
Created February 23, 2016 00:09
Show Gist options
  • Save joshma/8c0b2a3b60844efea2d5 to your computer and use it in GitHub Desktop.
Save joshma/8c0b2a3b60844efea2d5 to your computer and use it in GitHub Desktop.
diff --git i/example.js w/example.js
index ba2427a..2edc85e 100644
--- i/example.js
+++ w/example.js
@@ -11,10 +11,13 @@ const TodoItem = React.createClass({
id: React.PropTypes.number.isRequired,
}).isRequired,
},
+ deleteItem() {
+ this.props.deleteItem(this.props.item.id);
+ },
render() {
return (
<div>
- <button style={{width: 30}} onClick={this.props.deleteItem}>x</button>
+ <button style={{width: 30}} onClick={this.deleteItem}>x</button>
<span>{this.props.item.text}</span>
{this.props.tags.map((tag) => {
return <span key={tag} className="tag"> {tag}</span>;
@@ -26,6 +29,9 @@ const TodoItem = React.createClass({
const Todos = React.createClass({
mixins: [React.addons.LinkedStateMixin],
+ statics: {
+ tags: ['important', 'starred'],
+ },
propTypes: {
initialItems: React.PropTypes.arrayOf(React.PropTypes.shape({
text: React.PropTypes.string.isRequired,
@@ -60,8 +66,8 @@ const Todos = React.createClass({
</form>
{this.state.items.map((item) => {
return (
- <TodoItem key={item.id} item={item} tags={['important', 'starred']}
- deleteItem={this.deleteItem.bind(null, item.id)} />
+ <TodoItem key={item.id} item={item} tags={Todos.tags}
+ deleteItem={this.deleteItem} />
);
})}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment