Morhaus is correct, but this can be solved without bind
.
You can use an arrow function together with the class properties proposal:
class SomeClass extends React.Component {
changeContent = (e) => {
this.setState({inputContent: e.target.value})
}
render() {
return ;
}
}
Because the arrow function is declared in the scope of the constructor, and because arrow functions maintain this
from their declaring scope, it all works. The downside here is that these wont be functions on the prototype, they will all be recreated with each component. However, this isn't much of a downside since bind
results in the same thing.