Skip to content

Conversation

@ShaneChesnutt
Copy link
Contributor

No description provided.

@MatthewVita
Copy link
Member

MatthewVita commented Dec 12, 2016

@ShaneChesnutt actually you need to add the following to your example:

constructor(props) {
  super(props);

  // TODO: express this in terms of Redux (Shane, you can leave this todo in for now. Will get to it later)
  this.state = {
    foo: 'bar'
  };
    
  this.clickHandler = this.clickHandler.bind(this);
}

clickHandler() {
  console.log(this.state.foo); // => 'bar'
}

@MatthewVita
Copy link
Member

Can add a note saying "you'll need to bind the click handler to the class so that the this context (and, therefore, the component state) is accessible.

@MatthewVita
Copy link
Member

MatthewVita commented Dec 12, 2016

@ShaneChesnutt you're going to kill me, but I just realized one more thing we need to document with this section... how do you pass in the target data member with the click handler? For example, let's say you have the following data structure:

[{
  first: 'john',
  last: 'doe',
  email: 'john@doe.com'
}, {
  first: 'Mary',
  last: 'doe',
  email: 'mary@doe.com'
}]

and you ng-repeat it with an <button ng-click='vm.edit(row)'>edit</button> for each row, how does vm.edit function know which array item to set row.editMode = true for. We know this is rather easy in angular by looking for the index of the item in the larger array, but how would this work in React?

@ShaneChesnutt
Copy link
Contributor Author

ShaneChesnutt commented Dec 12, 2016 via email

@MatthewVita MatthewVita force-pushed the master branch 2 times, most recently from 1110535 to f8826e4 Compare January 28, 2017 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants