Created
August 31, 2016 12:31
-
-
Save caesarsol/be6c59a4d7a40712dae1d1e4df2918b0 to your computer and use it in GitHub Desktop.
React collection listener bindings
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 collection = [1, 2, 3, 4, 5, 6] | |
class B extends React.Component { | |
onLinkClick = (info) => { | |
alert(info) | |
} | |
render() { | |
return ( | |
<div> | |
{collection.map(n => | |
<Bb num={n} onLinkClick={this.onLinkClick} /> | |
)} | |
</div> | |
) | |
} | |
} | |
class Bb extends React.Component { | |
onClick = () => { | |
this.props.onLinkClick(this.props.num) | |
} | |
render() { | |
<a onClick={onClick} /> | |
} | |
} |
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 collection = [1, 2, 3, 4, 5, 6] | |
class A extends React.Component { | |
onLinkClick(info) { | |
alert(info) | |
} | |
render() { | |
return ( | |
<div> | |
{collection.map(n => | |
<a onLinkClick={() => this.onLinkClick(n)} /> | |
)} | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment