GoTeamEpsilon / angular-to-react-redux

Angular to React/Redux, a Guide for Angular v1 Experts Looking to Learn React/Redux
MIT License
107 stars 12 forks source link

ng-click #42

Closed ShaneChesnutt closed 7 years ago

MatthewVita commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

Okay I'll make sure to add that in

On Sun, Dec 11, 2016, 10:04 PM Matthew Vita notifications@github.com wrote:

@ShaneChesnutt https://github.com/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)>editfor edit row, how doesvm.editfunction know which array item to setrow.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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GoTeamEpsilon/angular-to-react/pull/42#issuecomment-266333404, or mute the thread https://github.com/notifications/unsubscribe-auth/AE9XHq974m1oO3awaPuLHjgeDMkKb0Mwks5rHLmngaJpZM4LKIeA .