Created
April 26, 2015 17:41
-
-
Save yefim/65293ef83cd6ec7572bc to your computer and use it in GitHub Desktop.
Using bind to set parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Item = React.createClass({ | |
render: function() { | |
return ( | |
<div onClick={this.props.handleClick.bind(this, this.props.item)}>{this.props.item}</div>; | |
); | |
} | |
}) | |
var List = React.createClass({ | |
handleClick: function(item) { | |
console.log(item); | |
}, | |
render: function() { | |
var list = ['a', 'b', 'c']; | |
var self = this; | |
var items = list.map(function(item) { | |
return <Item handleClick={self.handleClick} item={item} />; | |
}) | |
} | |
return ( | |
<div>{items}</div> | |
); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment