Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ export function useVirtual({
const reversedMeasurements = []

for (let i = 0, j = size - 1; i < size; i++, j--) {
const measuredSize = measuredCache[i]
const start = measurements[i - 1] ? measurements[i - 1].end : paddingStart
const size = measuredCache[i] || estimateSize(i)
const size =
typeof measuredSize === 'number' ? measuredSize : estimateSize(i)
const end = start + size
const bounds = { index: i, start, size, end }
measurements[i] = {
Expand Down
41 changes: 41 additions & 0 deletions src/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,47 @@ describe('useVirtual', () => {
rendered.getByText('Row 1')
})

it('should render given dynamic size', async () => {
function App() {
const parentRef = React.useRef()

const rowVirtualizer = useVirtual({
size: 20,
parentRef,
overscan: 5,
})

return (
<>
<Container ref={parentRef}>
<Inner
style={{
height: `${rowVirtualizer.totalSize}px`,
}}
>
{rowVirtualizer.virtualItems.map(virtualRow => (
<Row
key={virtualRow.index}
ref={virtualRow.measureRef}
style={{
height: `${virtualRow.size}px`,
transform: `translateY(${virtualRow.start}px)`,
}}
>
Row {virtualRow.index}
</Row>
))}
</Inner>
</Container>
</>
)
}

const rendered = render(<App />)

rendered.getByText('Row 1')
})

// it('scrolling utilities should work', async () => {
// function App() {
// const parentRef = React.useRef()
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1062,11 +1062,6 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@scarf/scarf@^1.0.0":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@scarf/scarf/-/scarf-1.0.4.tgz#d7c09e7d38428123df18a8d83a4bb5d09517d952"
integrity sha512-lkhjzeYyYAG4VvdrjvbZCOYzXH5vCwfzYj9xJ4zHDgyYIOzObZwcsbW6W1q5Z4tywrb14oG/tfsFAMMQPCTFqw==

"@sheerun/mutationobserver-shim@^0.3.2":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25"
Expand Down