Skip to content

Commit

Permalink
docs: exp virtual - remeasure when table state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Feb 4, 2025
1 parent 099e1a4 commit 9e6987d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/react/virtualized-columns-experimental/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ function App() {
setData(makeData(1_000, columns))
}, [columns])

// refresh data every 5 seconds
React.useEffect(() => {
const interval = setInterval(() => {
refreshData()
}, 5000)
return () => clearInterval(interval)
}, [refreshData])

const table = useReactTable({
data,
columns,
Expand Down Expand Up @@ -246,6 +254,10 @@ function TableBody({
},
})

React.useLayoutEffect(() => {
rowVirtualizer.measure()
}, [table.getState()])

const virtualRowIndexes = rowVirtualizer.getVirtualIndexes()

return (
Expand Down
12 changes: 12 additions & 0 deletions examples/react/virtualized-rows-experimental/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ function App() {
_setData(makeData(50_000))
}, [])

// refresh data every 5 seconds
React.useEffect(() => {
const interval = setInterval(() => {
refreshData()
}, 5000)
return () => clearInterval(interval)
}, [refreshData])

const table = useReactTable({
data,
columns,
Expand Down Expand Up @@ -189,6 +197,10 @@ function TableBodyWrapper({ table, tableContainerRef }: TableBodyWrapperProps) {
},
})

React.useLayoutEffect(() => {
rowVirtualizer.measure()
}, [table.getState()])

return (
<TableBody
rowRefsMap={rowRefsMap}
Expand Down

0 comments on commit 9e6987d

Please # to comment.