Skip to content

Commit 4f2a0f2

Browse files
committed
README: Update upgrade examples
1 parent 0727e22 commit 4f2a0f2

File tree

1 file changed

+56
-36
lines changed

1 file changed

+56
-36
lines changed

CHANGELOG.md

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,25 @@ This section contains a couple of examples for common upgrade paths. Please refe
112112
#### Before
113113

114114
```tsx
115+
import AutoSizer from "react-virtualized-auto-sizer";
115116
import { FixedSizeList, type ListChildComponentProps } from "react-window";
116117

117118
function Example({ names }: { names: string[] }) {
118119
const itemData = useMemo<ItemData>(() => ({ names }), [names]);
119120

120121
return (
121-
<FixedSizeList
122-
children={Row}
123-
height={150}
124-
itemCount={1000}
125-
itemData={itemData}
126-
itemSize={25}
127-
width={300}
128-
/>
122+
<AutoSizer>
123+
{({ height, width }) => (
124+
<FixedSizeList
125+
children={Row}
126+
height={height}
127+
itemCount={names.length}
128+
itemData={itemData}
129+
itemSize={25}
130+
width={width}
131+
/>
132+
)}
133+
</AutoSizer>
129134
);
130135
}
131136

@@ -177,6 +182,7 @@ function RowComponent({
177182
#### Before
178183

179184
```tsx
185+
import AutoSizer from "react-virtualized-auto-sizer";
180186
import { VariableSizeList, type ListChildComponentProps } from "react-window";
181187

182188
function Example({ items }: { items: Item[] }) {
@@ -190,14 +196,18 @@ function Example({ items }: { items: Item[] }) {
190196
);
191197

192198
return (
193-
<VariableSizeList
194-
children={Row}
195-
height={150}
196-
itemCount={1000}
197-
itemData={itemData}
198-
itemSize={itemSize}
199-
width={300}
200-
/>
199+
<AutoSizer>
200+
{({ height, width }) => (
201+
<VariableSizeList
202+
children={Row}
203+
height={height}
204+
itemCount={items.length}
205+
itemData={itemData}
206+
itemSize={itemSize}
207+
width={width}
208+
/>
209+
)}
210+
</AutoSizer>
201211
);
202212
}
203213

@@ -255,22 +265,27 @@ function RowComponent({ index, items, style }: RowComponentProps<RowProps>) {
255265
#### Before
256266

257267
```tsx
268+
import AutoSizer from "react-virtualized-auto-sizer";
258269
import { FixedSizeGrid, type GridChildComponentProps } from "react-window";
259270

260271
function Example({ data }: { data: Data[] }) {
261272
const itemData = useMemo<ItemData>(() => ({ data }), [data]);
262273

263274
return (
264-
<FixedSizeGrid
265-
children={Cell}
266-
columnCount={data[0]?.length ?? 0}
267-
columnWidth={100}
268-
height={150}
269-
itemData={itemData}
270-
rowCount={data.length}
271-
rowHeight={35}
272-
width={300}
273-
/>
275+
<AutoSizer>
276+
{({ height, width }) => (
277+
<FixedSizeGrid
278+
children={Cell}
279+
columnCount={data[0]?.length ?? 0}
280+
columnWidth={100}
281+
height={height}
282+
itemData={itemData}
283+
rowCount={data.length}
284+
rowHeight={35}
285+
width={width}
286+
/>
287+
)}
288+
</AutoSizer>
274289
);
275290
}
276291

@@ -326,6 +341,7 @@ function Cell({
326341
#### Before
327342

328343
```tsx
344+
import AutoSizer from "react-virtualized-auto-sizer";
329345
import { VariableSizeGrid, type GridChildComponentProps } from "react-window";
330346

331347
function Example({ data }: { data: Data[] }) {
@@ -346,16 +362,20 @@ function Example({ data }: { data: Data[] }) {
346362
);
347363

348364
return (
349-
<VariableSizeGrid
350-
children={Cell}
351-
columnCount={data[0]?.length ?? 0}
352-
columnWidth={columnWidth}
353-
height={150}
354-
itemData={itemData}
355-
rowCount={data.length}
356-
rowHeight={rowHeight}
357-
width={300}
358-
/>
365+
<AutoSizer>
366+
{({ height, width }) => (
367+
<VariableSizeGrid
368+
children={Cell}
369+
columnCount={data[0]?.length ?? 0}
370+
columnWidth={columnWidth}
371+
height={height}
372+
itemData={itemData}
373+
rowCount={data.length}
374+
rowHeight={rowHeight}
375+
width={width}
376+
/>
377+
)}
378+
</AutoSizer>
359379
);
360380
}
361381

0 commit comments

Comments
 (0)