T
TanStack2y ago
harsh-harlequin

Modify size of element on click

Each row can be clicked, which expands the row to show more data. I'm storing the state of what's open within a state object Record<string, boolean. My estimate size fn looks like:
estimateSize: (index) => {
return (open[filteredLogs[index].id] ? 150 : 28);
},
estimateSize: (index) => {
return (open[filteredLogs[index].id] ? 150 : 28);
},
This works when new data comes in, however useVirtualizer doesn't seem to re-render when my own state changes. Is there a way to handle this?
2 Replies
harsh-harlequin
harsh-harlequinOP2y ago
Ah got it, virtual.resizeItem(item, isOpen ? 150 : 28);
ambitious-aqua
ambitious-aqua2y ago
Ooo true, because now estimateSize is not a dependency when building measurements array it's not easy to update the sizes. We can change it but then estimateSize need to be stale, nevertheless we should change the signature of resizeItem, to resive key not a virutal item cc @Tanner Linsley what do you think?

Did you find this page helpful?