I have a list with around 2k items. If I use onClick on each child, I would end up with 2k listeners which is what I have currently. I would want to do something like making the parent component listen to the click events instead. But if I do that, I don't have reference to the child component which I need to call setState on. Also the list of child components can be filtered dynamically (using this.refs might be bad ?).
The best I can come up with is to make a hash of child components id mapping to child components in the parent and look up the view on click.
Just for illustration purposes:
var Parent = React.createClass({ shouldComponentUpdate: function() { return false; }, handler: function(e) { // look up from reference and set state }, componentWillUnmount: function() { // clean up reference }, render: function() { this.reference = {}; var items = []; for(var i = 0; i < this.props.items.length; i++) { var child = React.createClass(Child, {id: this.props.items[i].id}); items.push(child); reference[child.id] = child; } return React.createClass('div', {onClick: this.handler}, items); } }) I wonder if there is a React way of dealing with this.