Skip to content

Instantly share code, notes, and snippets.

@david-mart
Last active May 27, 2017 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-mart/8be4034196458da881825bb4f0d7504b to your computer and use it in GitHub Desktop.
Save david-mart/8be4034196458da881825bb4f0d7504b to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
class componentName extends Component {
constructor(props) {
super(props);
this.handleClicks = [];
this.props.friends.forEach(friend => {
this.handleClick[fiend.id] = this.handleClick.bind(this, friend.id);
})
}
this.handleClick(id, event) {
// ... do your stuff with id
}
render() {
const { friends } = this.props;
return (
<div>
fiends.map(friend => (
<Button onClick={this.handleClicks[friend.id]} />
))
</div>
);
}
}
export default componentName;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment