docs-i18n 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/admin/dist/server/server.js +32 -32
  2. package/package.json +1 -1
  3. package/template/app/routes/$lang.$project.$version.docs.$.tsx +2 -1
  4. package/template/app/routes/$lang.$project.$version.docs.framework.$framework.$.tsx +2 -0
  5. package/template/app/routes/$lang.$project.$version.docs.tsx +2 -1
  6. package/template/app/routes/$lang.$project.docs.$.tsx +2 -1
  7. package/template/app/routes/$lang.$project.docs.tsx +2 -1
  8. package/template/app/routes/$lang.docs.$.tsx +2 -1
  9. package/template/app/routes/$lang.docs.framework.$framework.$.tsx +2 -0
  10. package/template/app/routes/$lang.docs.tsx +2 -1
  11. package/template/app/utils/content-loader.ts +13 -2
  12. package/template/app/utils/docs.server.ts +17 -15
  13. package/template/content/blog/en/announcing-query-v5.md +110 -0
  14. package/template/content/blog/en/hello-world.md +26 -0
  15. package/template/content/blog/en/i18n-best-practices.md +57 -0
  16. package/template/content/blog/en/react-query-vs-swr.md +100 -0
  17. package/template/content/blog/en/state-management-2024.md +143 -0
  18. package/template/content/blog/en/tanstack-router-1.0.md +121 -0
  19. package/template/content/blog/ja/announcing-query-v5.md +110 -0
  20. package/template/content/blog/ja/hello-world.md +26 -0
  21. package/template/content/blog/zh-hans/announcing-query-v5.md +93 -0
  22. package/template/content/blog/zh-hans/hello-world.md +26 -0
  23. package/template/content/docs-i18n/docs.config.json +25 -0
  24. package/template/content/docs-i18n/en/architecture.md +335 -0
  25. package/template/content/docs-i18n/en/cli.md +13 -1
  26. package/template/content/docs-i18n/en/configuration.md +350 -0
  27. package/template/content/docs-i18n/en/deployment.md +222 -0
  28. package/template/content/docs-i18n/en/getting-started.md +189 -0
  29. package/template/content/docs.config.json +25 -0
  30. package/template/content/en/admin.md +151 -0
  31. package/template/content/en/architecture.md +222 -0
  32. package/template/content/en/cli.md +269 -0
  33. package/template/content/en/configuration.md +331 -0
  34. package/template/content/en/deployment.md +209 -0
  35. package/template/content/en/getting-started.md +168 -0
  36. package/template/content/form/docs.config.json +18 -0
  37. package/template/content/form/en/guides/validation.md +175 -0
  38. package/template/content/form/en/installation.md +63 -0
  39. package/template/content/form/en/overview.md +71 -0
  40. package/template/content/form/en/quick-start.md +121 -0
  41. package/template/content/form/ja/installation.md +63 -0
  42. package/template/content/form/ja/overview.md +71 -0
  43. package/template/content/form/zh-hans/installation.md +63 -0
  44. package/template/content/form/zh-hans/overview.md +71 -0
  45. package/template/content/query/docs.config.json +32 -0
  46. package/template/content/query/en/guides/mutations.md +126 -0
  47. package/template/content/query/en/guides/pagination.md +98 -0
  48. package/template/content/query/en/guides/queries.md +120 -0
  49. package/template/content/query/en/installation.md +78 -0
  50. package/template/content/query/en/overview.md +72 -0
  51. package/template/content/query/en/quick-start.md +108 -0
  52. package/template/content/query/ja/installation.md +78 -0
  53. package/template/content/query/ja/overview.md +72 -0
  54. package/template/content/query/zh-hans/guides/mutations.md +126 -0
  55. package/template/content/query/zh-hans/guides/pagination.md +98 -0
  56. package/template/content/query/zh-hans/guides/queries.md +120 -0
  57. package/template/content/query/zh-hans/installation.md +95 -0
  58. package/template/content/query/zh-hans/overview.md +72 -0
  59. package/template/content/query/zh-hans/quick-start.md +108 -0
  60. package/template/content/router/docs.config.json +18 -0
  61. package/template/content/router/en/guides/routing-concepts.md +131 -0
  62. package/template/content/router/en/installation.md +57 -0
  63. package/template/content/router/en/overview.md +74 -0
  64. package/template/content/router/en/quick-start.md +88 -0
  65. package/template/content/router/ja/installation.md +57 -0
  66. package/template/content/router/ja/overview.md +78 -0
  67. package/template/content/router/zh-hans/guides/routing-concepts.md +131 -0
  68. package/template/content/router/zh-hans/installation.md +57 -0
  69. package/template/content/router/zh-hans/overview.md +81 -0
  70. package/template/content/router/zh-hans/quick-start.md +88 -0
  71. package/template/content/table/docs.config.json +18 -0
  72. package/template/content/table/en/guides/column-definitions.md +135 -0
  73. package/template/content/table/en/installation.md +56 -0
  74. package/template/content/table/en/overview.md +79 -0
  75. package/template/content/table/en/quick-start.md +112 -0
  76. package/template/content/table/ja/installation.md +56 -0
  77. package/template/content/table/ja/overview.md +79 -0
  78. package/template/content/table/zh-hans/installation.md +56 -0
  79. package/template/content/table/zh-hans/overview.md +79 -0
  80. package/template/content/virtual/docs.config.json +18 -0
  81. package/template/content/virtual/en/guides/dynamic-sizing.md +129 -0
  82. package/template/content/virtual/en/installation.md +57 -0
  83. package/template/content/virtual/en/overview.md +74 -0
  84. package/template/content/virtual/en/quick-start.md +114 -0
  85. package/template/content/virtual/ja/installation.md +57 -0
  86. package/template/content/virtual/ja/overview.md +74 -0
  87. package/template/content/virtual/zh-hans/installation.md +57 -0
  88. package/template/content/virtual/zh-hans/overview.md +74 -0
@@ -0,0 +1,129 @@
1
+ ---
2
+ title: Dynamic Sizing
3
+ description: Learn how to handle dynamically sized elements with TanStack Virtual
4
+ ---
5
+
6
+ # Dynamic Sizing
7
+
8
+ By default, TanStack Virtual assumes all items have the same size. However, many real-world use cases require items with varying heights or widths. The `measureElement` option enables dynamic sizing by measuring actual DOM elements.
9
+
10
+ ## Basic Dynamic Sizing
11
+
12
+ To enable dynamic sizing, pass the `measureElement` function to your virtualizer and attach the provided ref to each item:
13
+
14
+ ```tsx
15
+ import { useVirtualizer } from '@tanstack/react-virtual'
16
+
17
+ function DynamicList({ items }: { items: string[] }) {
18
+ const parentRef = React.useRef<HTMLDivElement>(null)
19
+
20
+ const virtualizer = useVirtualizer({
21
+ count: items.length,
22
+ getScrollElement: () => parentRef.current,
23
+ estimateSize: () => 50, // estimated height in px
24
+ measureElement: (element) => {
25
+ return element.getBoundingClientRect().height
26
+ },
27
+ })
28
+
29
+ return (
30
+ <div ref={parentRef} style={{ height: '400px', overflow: 'auto' }}>
31
+ <div
32
+ style={{
33
+ height: `${virtualizer.getTotalSize()}px`,
34
+ width: '100%',
35
+ position: 'relative',
36
+ }}
37
+ >
38
+ {virtualizer.getVirtualItems().map((virtualItem) => (
39
+ <div
40
+ key={virtualItem.key}
41
+ ref={virtualizer.measureElement}
42
+ data-index={virtualItem.index}
43
+ style={{
44
+ position: 'absolute',
45
+ top: 0,
46
+ left: 0,
47
+ width: '100%',
48
+ transform: `translateY(${virtualItem.start}px)`,
49
+ }}
50
+ >
51
+ {items[virtualItem.index]}
52
+ </div>
53
+ ))}
54
+ </div>
55
+ </div>
56
+ )
57
+ }
58
+ ```
59
+
60
+ ## Estimated Size
61
+
62
+ The `estimateSize` function provides an initial size estimate before measurement occurs. A good estimate reduces layout shifts:
63
+
64
+ ```tsx
65
+ const virtualizer = useVirtualizer({
66
+ count: 10000,
67
+ getScrollElement: () => parentRef.current,
68
+ estimateSize: (index) => {
69
+ // Different estimates based on item type
70
+ if (items[index].type === 'header') return 80
71
+ if (items[index].type === 'image') return 200
72
+ return 50
73
+ },
74
+ })
75
+ ```
76
+
77
+ > [!NOTE]
78
+ > The `estimateSize` function receives the item index, so you can provide different estimates based on item data. Better estimates lead to smoother scrolling.
79
+
80
+ ## Performance Considerations
81
+
82
+ Dynamic sizing involves DOM measurement, which can be expensive. Here are some tips:
83
+
84
+ | Technique | Description |
85
+ |---|---|
86
+ | Good estimates | Provide accurate `estimateSize` values to minimize re-measurements |
87
+ | Overscan | Use `overscan` to render extra items outside the viewport |
88
+ | Stable keys | Provide stable `key` values to avoid unnecessary re-renders |
89
+ | CSS containment | Use `contain: strict` on the scroll container for better paint performance |
90
+
91
+ ```tsx
92
+ const virtualizer = useVirtualizer({
93
+ count: items.length,
94
+ getScrollElement: () => parentRef.current,
95
+ estimateSize: () => 50,
96
+ overscan: 5, // Render 5 extra items on each side
97
+ })
98
+ ```
99
+
100
+ ## Handling Resizes
101
+
102
+ When item content can change size after initial render (e.g., images loading, accordions expanding), you need to re-measure:
103
+
104
+ ```tsx
105
+ // Re-measure a specific item
106
+ virtualizer.resizeItem(index, newSize)
107
+
108
+ // Re-measure all items
109
+ virtualizer.measure()
110
+ ```
111
+
112
+ > [!WARNING]
113
+ > Calling `measure()` on every render will cause performance issues. Only call it when you know sizes have actually changed, such as after a window resize or content update.
114
+
115
+ ## Horizontal Dynamic Sizing
116
+
117
+ Dynamic sizing also works for horizontal lists. Use `horizontal: true` and measure width instead of height:
118
+
119
+ ```tsx
120
+ const virtualizer = useVirtualizer({
121
+ horizontal: true,
122
+ count: items.length,
123
+ getScrollElement: () => parentRef.current,
124
+ estimateSize: () => 100,
125
+ measureElement: (element) => {
126
+ return element.getBoundingClientRect().width
127
+ },
128
+ })
129
+ ```
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: Installation
3
+ description: How to install TanStack Virtual in your project
4
+ ---
5
+
6
+ # Installation
7
+
8
+ ## React
9
+
10
+ ```bash
11
+ npm install @tanstack/react-virtual
12
+ ```
13
+
14
+ ```bash
15
+ pnpm add @tanstack/react-virtual
16
+ ```
17
+
18
+ ```bash
19
+ yarn add @tanstack/react-virtual
20
+ ```
21
+
22
+ ```bash
23
+ bun add @tanstack/react-virtual
24
+ ```
25
+
26
+ ## Vue
27
+
28
+ ```bash
29
+ npm install @tanstack/vue-virtual
30
+ ```
31
+
32
+ ## Solid
33
+
34
+ ```bash
35
+ npm install @tanstack/solid-virtual
36
+ ```
37
+
38
+ ## Svelte
39
+
40
+ ```bash
41
+ npm install @tanstack/svelte-virtual
42
+ ```
43
+
44
+ ## Requirements
45
+
46
+ - React 18+ / Vue 3+ / Solid 1.6+ / Svelte 4+
47
+ - A scroll container with a fixed height (or width for horizontal lists)
48
+
49
+ ## Bundle Size
50
+
51
+ TanStack Virtual is extremely lightweight:
52
+
53
+ | Package | Size (gzipped) |
54
+ |---------|---------------|
55
+ | `@tanstack/virtual-core` | ~2.5 KB |
56
+ | `@tanstack/react-virtual` | ~3.5 KB |
57
+ | `@tanstack/vue-virtual` | ~3.5 KB |
@@ -0,0 +1,74 @@
1
+ ---
2
+ title: TanStack Virtual Overview
3
+ description: Headless UI for virtualizing large element lists at 60FPS
4
+ ---
5
+
6
+ # TanStack Virtual
7
+
8
+ TanStack Virtual provides headless utilities for virtualizing long lists of elements. It handles the logic of which items to render based on scroll position, while you retain full control over markup and styles.
9
+
10
+ ## Why Virtualization?
11
+
12
+ Rendering thousands of DOM nodes at once causes significant performance issues. Virtualization solves this by only rendering the items currently visible in the viewport, plus a small overscan buffer.
13
+
14
+ ## Features
15
+
16
+ - **Framework Agnostic** — Works with React, Vue, Solid, Svelte, and vanilla JS
17
+ - **Vertical & Horizontal** — Virtualize lists in any direction
18
+ - **Grid Virtualization** — Combine vertical and horizontal virtualizers for grids
19
+ - **Dynamic Row Heights** — Supports variable-size items with measurement
20
+ - **Sticky Items** — Pin items to the top or bottom of the scroll area
21
+ - **Scroll Restoration** — Maintain scroll position across navigation
22
+ - **Tiny Bundle** — Under 5KB gzipped
23
+
24
+ ## Basic Example
25
+
26
+ ```tsx
27
+ import { useVirtualizer } from '@tanstack/react-virtual'
28
+
29
+ function VirtualList() {
30
+ const parentRef = React.useRef<HTMLDivElement>(null)
31
+
32
+ const virtualizer = useVirtualizer({
33
+ count: 10000,
34
+ getScrollElement: () => parentRef.current,
35
+ estimateSize: () => 35,
36
+ })
37
+
38
+ return (
39
+ <div ref={parentRef} style={{ height: '400px', overflow: 'auto' }}>
40
+ <div
41
+ style={{
42
+ height: `${virtualizer.getTotalSize()}px`,
43
+ width: '100%',
44
+ position: 'relative',
45
+ }}
46
+ >
47
+ {virtualizer.getVirtualItems().map((virtualItem) => (
48
+ <div
49
+ key={virtualItem.key}
50
+ style={{
51
+ position: 'absolute',
52
+ top: 0,
53
+ left: 0,
54
+ width: '100%',
55
+ height: `${virtualItem.size}px`,
56
+ transform: `translateY(${virtualItem.start}px)`,
57
+ }}
58
+ >
59
+ Row {virtualItem.index}
60
+ </div>
61
+ ))}
62
+ </div>
63
+ </div>
64
+ )
65
+ }
66
+ ```
67
+
68
+ ## When to Use TanStack Virtual
69
+
70
+ - Lists with 100+ items
71
+ - Tables with many rows
72
+ - Chat/message interfaces
73
+ - Infinite scrolling feeds
74
+ - Any UI with dynamic, large datasets
@@ -0,0 +1,114 @@
1
+ ---
2
+ title: Quick Start
3
+ description: Get up and running with TanStack Virtual
4
+ ---
5
+
6
+ # Quick Start
7
+
8
+ ## Basic Vertical List
9
+
10
+ Create a virtualizer for a simple vertical list:
11
+
12
+ ```tsx
13
+ import { useVirtualizer } from '@tanstack/react-virtual'
14
+
15
+ function RowVirtualizer() {
16
+ const parentRef = React.useRef<HTMLDivElement>(null)
17
+
18
+ const rowVirtualizer = useVirtualizer({
19
+ count: 10000,
20
+ getScrollElement: () => parentRef.current,
21
+ estimateSize: () => 35,
22
+ overscan: 5,
23
+ })
24
+
25
+ return (
26
+ <div
27
+ ref={parentRef}
28
+ style={{ height: '400px', overflow: 'auto' }}
29
+ >
30
+ <div
31
+ style={{
32
+ height: `${rowVirtualizer.getTotalSize()}px`,
33
+ width: '100%',
34
+ position: 'relative',
35
+ }}
36
+ >
37
+ {rowVirtualizer.getVirtualItems().map((virtualRow) => (
38
+ <div
39
+ key={virtualRow.index}
40
+ style={{
41
+ position: 'absolute',
42
+ top: 0,
43
+ left: 0,
44
+ width: '100%',
45
+ height: `${virtualRow.size}px`,
46
+ transform: `translateY(${virtualRow.start}px)`,
47
+ }}
48
+ >
49
+ Row {virtualRow.index}
50
+ </div>
51
+ ))}
52
+ </div>
53
+ </div>
54
+ )
55
+ }
56
+ ```
57
+
58
+ ## Dynamic Row Heights
59
+
60
+ For variable-height items, provide a `measureElement` callback:
61
+
62
+ ```tsx
63
+ const rowVirtualizer = useVirtualizer({
64
+ count: items.length,
65
+ getScrollElement: () => parentRef.current,
66
+ estimateSize: () => 50, // estimated height
67
+ })
68
+
69
+ // In your rendered items:
70
+ {rowVirtualizer.getVirtualItems().map((virtualRow) => (
71
+ <div
72
+ key={virtualRow.index}
73
+ ref={rowVirtualizer.measureElement}
74
+ data-index={virtualRow.index}
75
+ >
76
+ {items[virtualRow.index].content}
77
+ </div>
78
+ ))}
79
+ ```
80
+
81
+ ## Horizontal List
82
+
83
+ Pass the `horizontal` option to virtualize a horizontal list:
84
+
85
+ ```tsx
86
+ const columnVirtualizer = useVirtualizer({
87
+ horizontal: true,
88
+ count: 10000,
89
+ getScrollElement: () => parentRef.current,
90
+ estimateSize: () => 100,
91
+ })
92
+ ```
93
+
94
+ ## Grid Virtualization
95
+
96
+ Combine two virtualizers for grid layouts:
97
+
98
+ ```tsx
99
+ const rowVirtualizer = useVirtualizer({
100
+ count: 10000,
101
+ getScrollElement: () => parentRef.current,
102
+ estimateSize: () => 35,
103
+ })
104
+
105
+ const columnVirtualizer = useVirtualizer({
106
+ horizontal: true,
107
+ count: 10000,
108
+ getScrollElement: () => parentRef.current,
109
+ estimateSize: () => 100,
110
+ })
111
+ ```
112
+
113
+ > [!NOTE]
114
+ > The `overscan` option controls how many items are rendered outside the visible area. Higher values reduce flicker during fast scrolling but use more memory.
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: インストール
3
+ description: プロジェクトに TanStack Virtual をインストールする方法
4
+ ---
5
+
6
+ # インストール
7
+
8
+ ## React
9
+
10
+ ```bash
11
+ npm install @tanstack/react-virtual
12
+ ```
13
+
14
+ ```bash
15
+ pnpm add @tanstack/react-virtual
16
+ ```
17
+
18
+ ```bash
19
+ yarn add @tanstack/react-virtual
20
+ ```
21
+
22
+ ```bash
23
+ bun add @tanstack/react-virtual
24
+ ```
25
+
26
+ ## Vue
27
+
28
+ ```bash
29
+ npm install @tanstack/vue-virtual
30
+ ```
31
+
32
+ ## Solid
33
+
34
+ ```bash
35
+ npm install @tanstack/solid-virtual
36
+ ```
37
+
38
+ ## Svelte
39
+
40
+ ```bash
41
+ npm install @tanstack/svelte-virtual
42
+ ```
43
+
44
+ ## 必要要件
45
+
46
+ - React 18+ / Vue 3+ / Solid 1.6+ / Svelte 4+
47
+ - 固定の高さ(水平リストの場合は幅)を持つスクロールコンテナ
48
+
49
+ ## バンドルサイズ
50
+
51
+ TanStack Virtual は非常に軽量です:
52
+
53
+ | パッケージ | サイズ(gzip) |
54
+ |---------|---------------|
55
+ | `@tanstack/virtual-core` | ~2.5 KB |
56
+ | `@tanstack/react-virtual` | ~3.5 KB |
57
+ | `@tanstack/vue-virtual` | ~3.5 KB |
@@ -0,0 +1,74 @@
1
+ ---
2
+ title: TanStack Virtual 概要
3
+ description: 大規模な要素リストを 60FPS で仮想化するヘッドレス UI
4
+ ---
5
+
6
+ # TanStack Virtual
7
+
8
+ TanStack Virtual は、長いリスト要素を仮想化するためのヘッドレスユーティリティを提供します。スクロール位置に基づいてどのアイテムをレンダリングするかのロジックを処理し、マークアップとスタイルの完全な制御はあなたに委ねます。
9
+
10
+ ## なぜ仮想化が必要なのか?
11
+
12
+ 一度に数千の DOM ノードをレンダリングすると、深刻なパフォーマンスの問題が発生します。仮想化は、ビューポートに現在表示されているアイテムと少量のオーバースキャンバッファのみをレンダリングすることで、この問題を解決します。
13
+
14
+ ## 特徴
15
+
16
+ - **フレームワーク非依存** — React、Vue、Solid、Svelte、バニラ JS で動作
17
+ - **垂直・水平** — 任意の方向でリストを仮想化
18
+ - **グリッド仮想化** — 垂直と水平のバーチャライザーを組み合わせてグリッドを実現
19
+ - **動的な行の高さ** — 可変サイズのアイテムと計測をサポート
20
+ - **固定アイテム** — スクロール領域の上部または下部にアイテムを固定
21
+ - **スクロール復元** — ナビゲーション間でスクロール位置を維持
22
+ - **極小バンドル** — gzip 後 5KB 未満
23
+
24
+ ## 基本的な例
25
+
26
+ ```tsx
27
+ import { useVirtualizer } from '@tanstack/react-virtual'
28
+
29
+ function VirtualList() {
30
+ const parentRef = React.useRef<HTMLDivElement>(null)
31
+
32
+ const virtualizer = useVirtualizer({
33
+ count: 10000,
34
+ getScrollElement: () => parentRef.current,
35
+ estimateSize: () => 35,
36
+ })
37
+
38
+ return (
39
+ <div ref={parentRef} style={{ height: '400px', overflow: 'auto' }}>
40
+ <div
41
+ style={{
42
+ height: `${virtualizer.getTotalSize()}px`,
43
+ width: '100%',
44
+ position: 'relative',
45
+ }}
46
+ >
47
+ {virtualizer.getVirtualItems().map((virtualItem) => (
48
+ <div
49
+ key={virtualItem.key}
50
+ style={{
51
+ position: 'absolute',
52
+ top: 0,
53
+ left: 0,
54
+ width: '100%',
55
+ height: `${virtualItem.size}px`,
56
+ transform: `translateY(${virtualItem.start}px)`,
57
+ }}
58
+ >
59
+ Row {virtualItem.index}
60
+ </div>
61
+ ))}
62
+ </div>
63
+ </div>
64
+ )
65
+ }
66
+ ```
67
+
68
+ ## TanStack Virtual を使うべき場面
69
+
70
+ - 100 件以上のアイテムを含むリスト
71
+ - 多数の行を持つテーブル
72
+ - チャット・メッセージインターフェース
73
+ - 無限スクロールフィード
74
+ - 大規模な動的データセットを含む任意の UI
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: 安装
3
+ description: 如何在项目中安装 TanStack Virtual
4
+ ---
5
+
6
+ # 安装
7
+
8
+ ## React
9
+
10
+ ```bash
11
+ npm install @tanstack/react-virtual
12
+ ```
13
+
14
+ ```bash
15
+ pnpm add @tanstack/react-virtual
16
+ ```
17
+
18
+ ```bash
19
+ yarn add @tanstack/react-virtual
20
+ ```
21
+
22
+ ```bash
23
+ bun add @tanstack/react-virtual
24
+ ```
25
+
26
+ ## Vue
27
+
28
+ ```bash
29
+ npm install @tanstack/vue-virtual
30
+ ```
31
+
32
+ ## Solid
33
+
34
+ ```bash
35
+ npm install @tanstack/solid-virtual
36
+ ```
37
+
38
+ ## Svelte
39
+
40
+ ```bash
41
+ npm install @tanstack/svelte-virtual
42
+ ```
43
+
44
+ ## 环境要求
45
+
46
+ - React 18+ / Vue 3+ / Solid 1.6+ / Svelte 4+
47
+ - 具有固定高度(或水平列表的固定宽度)的滚动容器
48
+
49
+ ## 包体积
50
+
51
+ TanStack Virtual 非常轻量:
52
+
53
+ | 包 | 大小(gzip) |
54
+ |---------|---------------|
55
+ | `@tanstack/virtual-core` | ~2.5 KB |
56
+ | `@tanstack/react-virtual` | ~3.5 KB |
57
+ | `@tanstack/vue-virtual` | ~3.5 KB |
@@ -0,0 +1,74 @@
1
+ ---
2
+ title: TanStack Virtual 概览
3
+ description: 无头 UI,以 60FPS 虚拟化大型元素列表
4
+ ---
5
+
6
+ # TanStack Virtual
7
+
8
+ TanStack Virtual 提供无头的虚拟化工具,用于处理长列表元素。它根据滚动位置处理渲染哪些项目的逻辑,同时你保留对标记和样式的完全控制。
9
+
10
+ ## 为什么需要虚拟化?
11
+
12
+ 一次渲染数千个 DOM 节点会导致严重的性能问题。虚拟化通过仅渲染当前在视口中可见的项目以及少量的预渲染缓冲来解决这个问题。
13
+
14
+ ## 特性
15
+
16
+ - **框架无关** — 支持 React、Vue、Solid、Svelte 和原生 JS
17
+ - **垂直和水平** — 任意方向虚拟化列表
18
+ - **网格虚拟化** — 结合垂直和水平虚拟化器实现网格
19
+ - **动态行高** — 支持可变大小的项目及测量
20
+ - **固定项目** — 将项目固定在滚动区域的顶部或底部
21
+ - **滚动恢复** — 在导航中保持滚动位置
22
+ - **极小的包体积** — gzip 后不到 5KB
23
+
24
+ ## 基本示例
25
+
26
+ ```tsx
27
+ import { useVirtualizer } from '@tanstack/react-virtual'
28
+
29
+ function VirtualList() {
30
+ const parentRef = React.useRef<HTMLDivElement>(null)
31
+
32
+ const virtualizer = useVirtualizer({
33
+ count: 10000,
34
+ getScrollElement: () => parentRef.current,
35
+ estimateSize: () => 35,
36
+ })
37
+
38
+ return (
39
+ <div ref={parentRef} style={{ height: '400px', overflow: 'auto' }}>
40
+ <div
41
+ style={{
42
+ height: `${virtualizer.getTotalSize()}px`,
43
+ width: '100%',
44
+ position: 'relative',
45
+ }}
46
+ >
47
+ {virtualizer.getVirtualItems().map((virtualItem) => (
48
+ <div
49
+ key={virtualItem.key}
50
+ style={{
51
+ position: 'absolute',
52
+ top: 0,
53
+ left: 0,
54
+ width: '100%',
55
+ height: `${virtualItem.size}px`,
56
+ transform: `translateY(${virtualItem.start}px)`,
57
+ }}
58
+ >
59
+ Row {virtualItem.index}
60
+ </div>
61
+ ))}
62
+ </div>
63
+ </div>
64
+ )
65
+ }
66
+ ```
67
+
68
+ ## 何时使用 TanStack Virtual
69
+
70
+ - 包含 100+ 项的列表
71
+ - 多行的表格
72
+ - 聊天/消息界面
73
+ - 无限滚动的信息流
74
+ - 任何包含大量动态数据集的 UI