How to use setState inside handsontable functions

Tags: #<Tag:0x00007efc72848238>

Hi team,

how do we change state of react component inside handsontable functions? for example, I would like to change state in following example-

afterCreateRow: function(index, amount){
let newArr = [];
newArr.push(amount);
this.setState( {updatedArray: newArr} );

      }

but this is not instance of react component and i cannot call setState(). how do i call setState() here?

Hey @rohit.parwal

I just got a hint that you should replace afterCreateRow: function () {} with afterCreateRow() {} or use the arrow function afterCreateRow: () => {} then you’ll 90% sure that this is the component.
You can also define var self = this; and use it within the self.setState() function.

thanks,
if I use the arrow function afterCreateRow: () => {} then i would get react component instance. But in this case, how do i get instance of handsontable?

I think that this demo will help https://stackblitz.com/edit/angular-5ykm8c-zoo5de?file=src/app/heroes/heroes.component.ts

Let me know if it works for you.

can you pls provide similar example with React? thanks.

Hey @rohit.parwal

I have one similar example here https://codepen.io/anon/pen/GPqQwd?editors=0010

Let me know if it works for you.