Last active
October 24, 2021 23:44
-
-
Save YousraBD/45adac445c5b0abb827f2ed8ba42944e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<List | |
itemKey={faker.datatype.uuid} | |
itemData={data} | |
innerElementType="ul" | |
itemCount={data.length} | |
itemSize={20} | |
height={700} | |
width={400} | |
> | |
{({ data, index, style }) => { | |
return <li style={style}>{data[index]}</li>; | |
}} | |
</List> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ yarn add faker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FixedSizeList as List } from "react-window"; | |
const App = () => { | |
const [data, setData] = useState(() => | |
Array.from({ length: 10000 }, faker.address.city) | |
); | |
const reverse = () => { | |
setData((data) => data.slice().reverse()); | |
}; | |
return ( | |
<main> | |
<button onClick={reverse}>Reverse</button> | |
<List | |
innerElementType="ul" | |
itemCount={data.length} | |
itemSize={20} | |
height={700} | |
width={400} | |
> | |
{({ index, style }) => { | |
return ( | |
<li style={style}> | |
{data[index]} | |
</li> | |
); | |
}} | |
</List> | |
</main> | |
); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import * as faker from "faker"; | |
const App = () => { | |
const [data, setData] = useState(() => | |
Array.from({ length: 10000 }, faker.address.city) | |
); | |
return ( | |
<main> | |
<ul style={{ width: "400px", height: "700px", overflowY: "scroll" }}> | |
{data.map((city, i) => ( | |
<li key={i + city}>{city}</li> | |
))} | |
</ul> | |
</main> | |
); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<List | |
useIsScrolling={true} | |
itemCount={data.length} | |
itemSize={20} | |
height={700} | |
width={400} | |
> | |
{({ index, style, isScrolling }) => | |
isScrolling ? ( | |
<Skeleton style={style} /> | |
) : ( | |
<ExpensiveItem index={index} style={style} /> | |
) | |
} | |
</List>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<List | |
itemData={data} | |
innerElementType="ul" | |
itemCount={data.length} | |
itemSize={20} | |
height={700} | |
width={400} | |
> | |
{({ data, index, style }) => { | |
return <li style={style}>{data[index]}</li>; | |
}} | |
</List> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ yarn add react-window # the library | |
$ yarn add -D @types/react-window # auto-completion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => { | |
const [data, setData] = useState(() => | |
Array.from({ length: 10000 }, faker.address.city) | |
); | |
const reverse = () => { | |
setData((data) => data.slice().reverse()); | |
}; | |
return ( | |
<main> | |
<button onClick={reverse}>Reverse</button> | |
<ul style={{ width: "400px", height: "700px", overflowY: "scroll" }}> | |
{data.map((city, i) => ( | |
<li style={{ height: "20px" }} key={i + city}>{city}</li> | |
))} | |
</ul> | |
</main> | |
); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FixedSizeGrid as Grid } from "react-window"; | |
import * as faker from "faker"; | |
const COLUMNS = 18; | |
const ROWS = 30; | |
const data = Array.from({ length: ROWS }, () => | |
Array.from({ length: COLUMNS }, faker.internet.avatar) | |
); | |
function App() { | |
return ( | |
<Grid | |
columnCount={COLUMNS} | |
rowCount={ROWS} | |
columnWidth={50} | |
rowHeight={50} | |
height={500} | |
width={600} | |
> | |
{({ rowIndex, columnIndex, style }) => { | |
return <img src={data\[rowIndex\][columnIndex]} alt="" />; | |
}} | |
</Grid> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the example in datatype.uuid.js:
<List
itemKey={faker.datatype.uuid}
itemData={data}
innerElementType="ul"
itemCount={data.length}
itemSize={20}
height={700}
width={400}
{({ data, index, style }) => {
return
}}
I was having a hard time trying to destructure the list children props from