Browse Source

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.
main
Ray Dai 8 years ago
committed by Brandon Dail
parent
commit
38aefe5d7b
  1. 6
      tips/14-communicate-between-components.md

6
tips/14-communicate-between-components.md

@ -13,8 +13,8 @@ For child-parent communication:
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:
```js
var handleClick = function(i, props) {
console.log('You clicked: ' + props.items[i]);
var handleClick = function(i, items) {
console.log('You clicked: ' + items[i]);
}
function GroceryList(props) {
@ -22,7 +22,7 @@ function GroceryList(props) {
<div>
{props.items.map(function(item, i) {
return (
<div onClick={handleClick.bind(this, i, props)} key={i}>{item}</div>
<div onClick={handleClick.bind(this, i, props.items)} key={i}>{item}</div>
);
})}
</div>

Loading…
Cancel
Save