mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-22 03:42:14 +00:00
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.
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user