Skip to content

Instantly share code, notes, and snippets.

@caesarsol
Created August 31, 2016 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caesarsol/be6c59a4d7a40712dae1d1e4df2918b0 to your computer and use it in GitHub Desktop.
Save caesarsol/be6c59a4d7a40712dae1d1e4df2918b0 to your computer and use it in GitHub Desktop.
React collection listener bindings
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} />
}
}
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