HI,
I’m learning the events:
I don’t understand this line, the bind method attach this to update, but this.update are not an argument in the constructor?
I’ll expect in object programming, constructor ( update ) { this.update = …
this.update = this.update.bind(this) //udate method and bind to the context
my all code works well:
import React from 'react'
class SynteticEventSystem extends React.Component {
constructor(){
super()
this.state = { currentEvent: '------' }
this.update = this.update.bind(this) //udate method and bind to the context
}
update(e){
this.setState({currentEvent: e.type});
}
render() {
return (
<div>
<textarea
onKeyPress={this.update}
onCopy={this.update}
onCut={this.update}
onPaste={this.update}
onFocus={this.update}
onBlur={this.update}
onDoubleClick={this.update}
onTouchStart={this.update}
onTouchMove={this.update}
onTouchEnd={this.update}
rows='3'
cols='10' />
<h1> { this.state.currentEvent }</h1>
</div>
);
}
}
export default SynteticEventSystem