Skip to content Skip to sidebar Skip to footer

React.js - "this" Undefined Even After Binding

I am trying to capture onChange event of the input and calling setState with the new value, but as soon as I type in the input I get: Uncaught TypeError: Cannot read property 'set

Solution 1:

Assign this.handleChange.bind(this)(bind - returns new reference to function) to this.handleChange., because this.handleChange have to refer to new function which returns .bind

constructor(props) {
  super(props)
  this.handleChange = this.handleChange.bind(this)
  this.state = {contents: 'initialContent'}
}

Post a Comment for "React.js - "this" Undefined Even After Binding"