Skip to content

Commit 510ee1b

Browse files
Optimize useDataTableUrlState with memoization and fix lint errors
Co-authored-by: jaruesink <4207065+jaruesink@users.noreply.github.com>
1 parent 71272b8 commit 510ee1b

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

packages/components/benchmarks/perf-benchmark.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
import { performance } from 'perf_hooks';
1+
import { performance } from 'node:perf_hooks';
32
import { dataTableRouterParsers } from '../src/remix-hook-form/data-table-router-parsers';
43

54
const ITERATIONS = 10000;

packages/components/src/remix-hook-form/use-data-table-url-state.test.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { renderHook, act } from '@testing-library/react';
2-
import { MemoryRouter, useLocation } from 'react-router';
3-
import { describe, it, expect } from 'vitest';
1+
import { act, renderHook } from '@testing-library/react';
2+
import type React from 'react';
3+
import { type Location, MemoryRouter, useLocation } from 'react-router';
4+
import { describe, expect, it } from 'vitest';
45
import { useDataTableUrlState } from './use-data-table-url-state';
5-
import React from 'react';
66

77
describe('useDataTableUrlState', () => {
88
it('should parse initial state from URL', () => {
99
const wrapper = ({ children }: { children: React.ReactNode }) => (
10-
<MemoryRouter initialEntries={['/?search=initial&page=2&pageSize=20']}>
11-
{children}
12-
</MemoryRouter>
10+
<MemoryRouter initialEntries={['/?search=initial&page=2&pageSize=20']}>{children}</MemoryRouter>
1311
);
1412

1513
const { result } = renderHook(() => useDataTableUrlState(), { wrapper });
@@ -20,7 +18,7 @@ describe('useDataTableUrlState', () => {
2018
});
2119

2220
it('should update URL state', () => {
23-
let testLocation: any;
21+
let testLocation: Location | undefined;
2422

2523
const LocationSpy = () => {
2624
testLocation = useLocation();
@@ -41,6 +39,6 @@ describe('useDataTableUrlState', () => {
4139
});
4240

4341
expect(result.current.urlState.search).toBe('updated');
44-
expect(testLocation.search).toContain('search=updated');
42+
expect(testLocation?.search).toContain('search=updated');
4543
});
4644
});

0 commit comments

Comments
 (0)