rangeme rangeme - 1 year ago 190
Javascript Question

How can I pass variables to function from onClick in Meteor/React?

I have some code like so

goToEvent() {

return (
{e.users.map( (id) => {
<ListItem key={id} primaryText="Event" onClick={this.goToEvent.bind(this)} />

I'm unsure how to get the id parameter into the

I actually have the bind in the constructor so I tried having
but realized that was incorrect because it was calling the method immediately.

Any help or direction would be appreciated.

Answer Source

For react the solution is

return ( {e.users.map( (id) => { <ListItem key={id} primaryText="Event" onClick={this.goToEvent.bind(this, id)} /> })} );

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download