0

I have a basic React question. Can you tell me what is the difference between the two onDismiss methods?

class App extends Component {

constructor (props){
super(props)
this.state = {..}
}

onDismiss (id){ ... }

onDismiss = (id) =>{ ... }


render(){...}
}

Thank you!!

Ade N
  • 145
  • 1
  • 1
  • 12
  • The first doesn't have `this` from the class bound to it, but the second one does, being an arrow function. This is a javascript syntax, unrelated to React, BTW. – Drew Reese Apr 30 '20 at 07:59
  • Drew Reese, correct me if I am wrong. So, you are saying that the first one doesn't need a `this.onDismiss = this.onDismiss.bind(this)` in the constructor but the second one does? – Ade N Apr 30 '20 at 08:11
  • Other way around. The first one needs to be bound in the constructor, the second one doesn't. – Drew Reese Apr 30 '20 at 08:14
  • Fantastic, now it makes sense. Thank you!! – Ade N Apr 30 '20 at 08:22

0 Answers0