Using setState in HoT resetting the red color invalid cell

Tags: #<Tag:0x00007f8b233d9d38>

I have used Handsontable in a react application.
I need to open a pop-up on click of a certain button. To open the button I need to use react’s setState to set the variable to true.

When using the setState() in react, all the red highlighted cells are resetting back to a white.
I need to have that red highlighted cell as red even after setState() call.

Below is my sample code showing this issue:-

Enter any alphabetic characters in the column named “Number”. When it highlights as red(i.e. invalid). Click on the Click Me! button which is using setState() to add another variable in the object. Which is going to reset the red color to a white.

import React from ‘react’;
import { HotTable } from ‘@handsontable/react’;
import ‘handsontable/dist/handsontable.full.css’;

class App extends React.Component {
constructor(props) {
super(props);

this.state = {
  settings: {
    data: [
      [1, 'a'],
      [2, 'b']
    ],
    colHeaders: ['Number', 'Text'],
    columns: [
      {type: 'numeric'},
      {type: 'text'}
    ],
    },
  };
this.hotTableComponent = React.createRef();

}

handleClick = () => {
this.setState({
testValue: true,
});
}

render() {
return (



Click Me!



);
}
}

export default App;

Demo:- https://codepen.io/PrawalSharma/pen/xNLMgM

Just enter an invalid value(alphabets) in the column “Number”.
Click on somewhere else. It will turn to red.

Now click on the button above the HoT. The red color should disappear.

that works on my Chrome 74/Win 10.

The video showcasing the issue on my system:-

My chrome version:-

The red color should not disappear on click of the button. The button is just using setState function of react.

Ok, now I can understand. I’ll check it out and share my thoughts as soon as possible.

I got a message from our developer

I use shouldComponentUpdate() { return false; }
to break render cycle.

https://codepen.io/handsoncode/pen/dEZMxy?editors=0110

Thanks for such a quick reply but using shouldComponentUpdate() stops rendering.

Take for example my updated code where I am setting some value using setState() but using shouldComponentUpdate() the value is not rendered.
While removing shouldComponentUpdate() value appears.

Video:- https://drive.google.com/file/d/1OUwxw9ow_n1L1W6fLP_kjMJTdOwF9X6s/view?usp=sharing
Demo:- https://codepen.io/PrawalSharma/pen/KLyaMR?editors=0110

Hey @prawal.sharma

Another approach - https://codepen.io/handsoncode/pen/JqMXZa?editors=1010
This time I break up app to two component with shared state. This way we don’t render all app, but only one of them when needed.

Okay so thanks for the update. I understand we need to create multiple components to stop setState() from rendering the HoT table.

Is there any issue where react setState() causes HoT to lose color.

I mean what happens behind the scenes when we use setState() and use the same component(just curious).

I got a tip that this is a great source of information https://stackoverflow.com/questions/45273948/what-happens-when-setstate-function-is-called