From 2fd497d2c51ab0cd21b6d16941852db202d1b8db Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Tue, 31 Dec 2013 21:23:28 -0500 Subject: [PATCH] docs tips fix small typo and code --- tips/15-expose-component-functions.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tips/15-expose-component-functions.md b/tips/15-expose-component-functions.md index 2a59a126..acf5ab92 100644 --- a/tips/15-expose-component-functions.md +++ b/tips/15-expose-component-functions.md @@ -29,9 +29,10 @@ var Todos = React.createClass({ return {items: ['Apple', 'Banana', 'Cranberry']}; }, - handleClick: function(i) { - var items = this.state.items; - items.splice(i, 1); + handleClick: function(index) { + var items = this.state.items.filter(function(item, i) { + return index !== i; + }); this.setState({items: items}, function() { if (items.length === 1) { this.refs.item0.animate(); @@ -56,4 +57,4 @@ var Todos = React.createClass({ React.renderComponent(, mountNode); ``` -Alternatively, you could have achieve this by passing the `todo` an `isLastUnfinishedItem` prop, let it check this prop in `componentDidUpdate`, then animate itself; however, this quickly gets messy if you pass around different props to control animations. +Alternatively, you could have achieved this by passing the `todo` an `isLastUnfinishedItem` prop, let it check this prop in `componentDidUpdate`, then animate itself; however, this quickly gets messy if you pass around different props to control animations.