I am using the React version of Handsontable. When placed inside a parent component, any changes to the parent component naturally re-render the child component, which in my case is the Handsontable.
So far I have not noticed any related issues other than cell validation, which completely resets when the parent component causes a child component re-render. I am hoping there is some React or Handsontable magic to solve this, as I have tried every combination of Handsontable hooks, events, and React effects to resolve this.
Here is a simple example with two major problems that I did not encounter when I used the plain JS version of Handsontable.
- Validation does not occur on data load, and the
afterLoadData
prop does not provide a reference to the HotTable ref, so I’m not sure how we can validate initial data. - More importantly, any re-render coming from the parent clears all validation.
All of the data and HTML and JSX (with minor excecptions) is from the React example
To see what I mean, please observe
- No initial cell validation
- Change any of the values in Company Name. There is a validator setup such that any value is an error. Now click the “Click me” button at the top of the page. This causes the parent component to re-render causing the Table to re-render and the result is all validation is reset.
Please note I have of course trivialized this into a simple example. In our real-world app, we have some things in the parent component that may completely re-set the state of the data
property, and there are a few callbacks and other props passed to Table
from the parent.
https://codesandbox.io/p/sandbox/qjhf7p?file=%2Fsrc%2Findex.tsx