setState in AfterHideColumns make handsontable re-render again and again

Tags: #<Tag:0x00007fce774573e0> #<Tag:0x00007fce77457278>

When I am setting a state with the setState method to store the columnHiding index in the afterHideColumn Hook then table re-render again and again until page broke
please help

Hi @siddhantjain15298

I’ve downloaded a small React here where I control the state of the hidden columns. Could you alter ti so it shows your current configuration?

Hi @aleksandra_budnik
But i want to setState in afterHideColumn Hook which goes render into infinite loop
and if i am not setting a state then other setState calls and reset the hidden columns configuration

So is the afterHideColumns hook only used to update the state of hidden columns or does it do anything else? I will prepare a demo for that.

ps. do you store hidden indexes as an array in the state or you prefer to store the indexes of visible columns?

Yeah I just want to maintain a state of hidding column index using afterHideColumns and afterUnhideColumns hooks in handsontable whenever user click hide column and show column from context menu

I think you are trying to keep the state of hidden columns on every re-render. by default handsontable resets the hidden columns when page re-renders.
you don’t need to setState directly in afterHideColumns etc. Handsontable manages it by itself. you just need to store every hidden column in localStorage etc and on component mount you can retrieve that list and hide the columns.

  const afterColumnsHiddenStateChange = (
_: number[],
destinationHideConfig: number[]
) => {
!firstLoad &&

 firstLoad && setFirstLoad(!firstLoad);


const afterColumnsUnhide = (_: number[], destinationHideConfig: number[]) => {

This is how you can set hidden columns on component mount

        let existingHiddenCols: number[] = JSON.parse(
             )  || `[]`

}, [] )

now you can use hiddenColumns state in <HotTable />

Thank you for your input @jamshaidbutt055
I can also add that the solution you wanted to use produces React error #185 - infinite loop.