I\'ve seen code using Javascript classes use the following form (example is React):
class UserProfile extends Component {
state = {
open: false
}
hand
It's about the context of this
inside of your method. If you would implement it like your second example, this
won't reference the component instance, using the arrow function like in your first example this
references the component instance. (Due to not using React.createClass
).
For your second example you have to do this.handleOpen = this.handleOpen.bind(this)
inside your constructor.
EDIT: For details about arrow functions
see the answer from Chris
.