1

I am attempting to override a keyEvent for a handsontable. The code runs but will get the error "Uncaught TypeError: this.handleSearchNext is not a function" But it is a function defined, so I'm not sure why I am getting this error.

async componentWillReceiveProps(newProps) {
    this.hotTable.updateSettings({
      afterDocumentKeyDown(e) {
        if (e.key === 'Enter') {
          this.handleSearchNext(e)
          e.stopPropagation()
          console.log('Stopped propigation in table', e)
        }
      }
    })
}
.
.
.
handleSearchNext = (e) => {...}
Darren rogers
  • 627
  • 2
  • 8
  • 17
  • You have to bind method to `this`: in the constructor: `this.handleSearchNext = this.handleSearchNext.bind(this);` – Randy Casburn Jun 11 '19 at 05:35
  • Possible duplicate of [Unable to access React instance (this) inside event handler](https://stackoverflow.com/questions/29577977/unable-to-access-react-instance-this-inside-event-handler) – wentjun Jun 11 '19 at 05:37
  • @RandyCasburn I thought since it was an arrow function it doesnt need to be specifically bound. Doesn't ()=> automatically bind the function? – Darren rogers Jun 11 '19 at 05:44

0 Answers0