Skip to content

Commit

Permalink
v.2.3.0
Browse files Browse the repository at this point in the history
- improved virtualization rows rendering speed when scrolled for long distances / overall
  • Loading branch information
ixrock committed Nov 28, 2024
1 parent 96ccdf3 commit 5379dc1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-react-table-grid",
"version": "2.2.0",
"version": "2.3.0",
"description": "Easy to use and powerful react table-grid layout based on CSS-grid",
"license": "MIT",
"author": "ixrock",
Expand Down
7 changes: 3 additions & 4 deletions src/table/useVirtualization.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useLayoutEffect, useState } from "react";
import type { TableDataRow } from "./index";
import throttle from "lodash/throttle";

export interface VirtualizationOptions<DataItem = any> {
parentElemRef: React.RefObject<HTMLElement>;
Expand Down Expand Up @@ -52,8 +51,8 @@ export function useVirtualization<D>(options: VirtualizationOptions<D>) {
setMaxScrollHeight(rows.length * rowSize);
setViewportSize(rootElem.offsetHeight);

const onScroll = throttle(() => {
window.requestIdleCallback(() => {
const onScroll = () => {
window.requestAnimationFrame(() => {
const { scrollTop } = rootElem;
const scrolledRowsInfo = getScrolledRowsInfo({
rows,
Expand All @@ -63,7 +62,7 @@ export function useVirtualization<D>(options: VirtualizationOptions<D>) {
setScrollPos(scrollTop);
setScrolledRowsCount(scrolledRowsInfo.count);
});
}, 50);
};

const resizeObserver = new ResizeObserver(([entry]) => {
const viewportSize = Math.round(entry.contentRect.height);
Expand Down

0 comments on commit 5379dc1

Please sign in to comment.