diff --git a/src/index.js b/src/index.js
index 9a8ef8ed..7e480f7a 100644
--- a/src/index.js
+++ b/src/index.js
@@ -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] = {
diff --git a/src/tests/index.test.js b/src/tests/index.test.js
index dd7d36c6..e78eff6d 100644
--- a/src/tests/index.test.js
+++ b/src/tests/index.test.js
@@ -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 (
+ <>
+
+
+ {rowVirtualizer.virtualItems.map(virtualRow => (
+
+ Row {virtualRow.index}
+
+ ))}
+
+
+ >
+ )
+ }
+
+ const rendered = render()
+
+ rendered.getByText('Row 1')
+ })
+
// it('scrolling utilities should work', async () => {
// function App() {
// const parentRef = React.useRef()
diff --git a/yarn.lock b/yarn.lock
index a2b708c0..c332a97a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -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"