wenqili / knowtebook

0 stars 0 forks source link

React bind #5

Open wenqili opened 5 years ago

wenqili commented 5 years ago

Handling Events and pass value ES 6 arrow function

// bind in constructor
constructor() {
  this.handleClick = this.handleClick.bind(this)
}

handleClick(col){
...
}

return (
  <th value={column} onClick={() => this.handleClick(column)}>{column}</th>
);

ES5

handleClick(col){
...
}

return (
  <th value={column} onClick={() => this.handleClick.bind(this, column)}>{column}</th>
);

Or create sub-component to prevent extra re-renders link