Skip to content

Commit 88b8457

Browse files
committed
Code prettier. Increase render speed. Update version
1 parent 6ac6b15 commit 88b8457

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

demo/src/app/page.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ export default function Home() {
1818
<td>ID</td>
1919
<td width="25%">Name</td>
2020
<td width="25%">Surname</td>
21+
<td>ID</td>
22+
<td width="25%">Name</td>
23+
<td width="25%"> Surname</td>
24+
<td>ID</td>
25+
<td width="25%">Name</td>
26+
<td width="25%">Surname</td>
2127
</tr>
2228
</thead>
2329
<tbody>
24-
{Array(100)
30+
{Array(300)
2531
.fill(null)
2632
.map((item, index) => (
2733
<tr key={index}>
@@ -31,6 +37,12 @@ export default function Home() {
3137
<td>10000000000</td>
3238
<td>10000000000</td>
3339
<td>10000000000</td>
40+
<td>10000000000</td>
41+
<td>10000000000</td>
42+
<td>10000000000</td>
43+
<td>10000000000</td>
44+
<td>10000000000</td>
45+
<td>10000000000</td>
3446
</tr>
3547
))}
3648
</tbody>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-table-scroll",
3-
"version": "0.0.8b",
3+
"version": "0.0.9b",
44
"author": "Ontuzhev Viacheslav (Natterum)",
55
"license": "MIT",
66
"main": "./dist/cjs/index.js",

src/components/ReactTableScroll.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,28 @@ const ReactTableScroll = ({ children }: IProps) => {
1212
const horizontalScrollRef = useRef<HTMLDivElement | any>(null);
1313
const targetRef = useRef<HTMLDivElement | any>(null);
1414
const { width, height } = useResizeDetector({ targetRef });
15+
const tableContainerRef = useRef<HTMLDivElement | any>(null);
1516
const tableWrapperRef = useRef<HTMLDivElement | any>(null);
16-
const [tableLeftPos, setTableLeftPos] = useState<number>(0);
1717

1818
const diffSizes = (): boolean => {
19-
return tableWrapperRef.current?.clientWidth > targetRef.current?.clientWidth;
19+
return tableContainerRef.current?.clientWidth > targetRef.current?.clientWidth;
2020
};
2121

2222
const handleResize = () => {
2323
const setValue = (value: number) => {
2424
setHorizontalScrollStyle({ width: value });
2525
};
2626
if (diffSizes()) {
27-
setValue(tableWrapperRef.current?.clientWidth);
27+
setValue(tableContainerRef.current?.clientWidth);
2828
} else {
2929
setValue(0);
3030
}
3131
};
3232

3333
const onTableHorizontalScroll = () => {
3434
const posX: number = horizontalScrollRef.current?.scrollLeft ?? 0;
35-
setTableLeftPos(posX);
35+
const posY: number = horizontalScrollRef.current?.scrollTop ?? 0;
36+
tableWrapperRef.current.scrollTo(posX, posY);
3637
};
3738

3839
useEffect(() => {
@@ -41,8 +42,8 @@ const ReactTableScroll = ({ children }: IProps) => {
4142

4243
return (
4344
<div className="rts__wrapper" ref={targetRef}>
44-
<div className="rts-table__wrapper">
45-
<div className="rts-table__container" ref={tableWrapperRef} style={{ left: -tableLeftPos }}>
45+
<div className="rts-table__wrapper" ref={tableWrapperRef}>
46+
<div className="rts-table__container" ref={tableContainerRef}>
4647
{children}
4748
</div>
4849
</div>

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import ReactTableScroll from './components/ReactTableScroll';
22

3-
export { ReactTableScroll };
3+
export { ReactTableScroll };

0 commit comments

Comments
 (0)