Update 14-communicate-between-components.md (#7680)
To demonstrate multiple arguments `bind(this, arg1, arg2, ...)`, also not to pass in for than what `handleClick` needed, namely props, or maybe even pass item itself, etc. Going to change the kor file after review.
Ray Dai committed
Sep 9, 2016 at 01:20 UTC
05cbc9340120fec618c728e9d71db811a5149c45
1 file changed
+3
-3
docs/tips/14-communicate-between-components.md
+3
-3
@@ -13,8 +13,8 @@ For child-parent communication:
13
Say your `GroceryList` component has a list of items generated through an array. When a list item is clicked, you want to display its name:
14
15
```js
16
-var handleClick = function(i, props) {
17
- console.log('You clicked: ' + props.items[i]);
16
+var handleClick = function(i, items) {
17
+ console.log('You clicked: ' + items[i]);
18
}
19
20
function GroceryList(props) {
@@ -22,7 +22,7 @@ function GroceryList(props) {
22
<div>
23
{props.items.map(function(item, i) {
24
return (
25
- <div onClick={handleClick.bind(this, i, props)} key={i}>{item}</div>
25
+ <div onClick={handleClick.bind(this, i, props.items)} key={i}>{item}</div>
26
);
27
})}
28
</div>