()
| 291 | } |
| 292 | |
| 293 | function RowVirtualizerExperimental() { |
| 294 | const parentRef = React.useRef<HTMLDivElement>(null) |
| 295 | const innerRef = React.useRef<HTMLDivElement>(null) |
| 296 | const rowRefsMap = React.useRef(new Map<number, HTMLDivElement>()) |
| 297 | |
| 298 | const [enabled, setEnabled] = React.useState(true) |
| 299 | |
| 300 | const count = sentences.length |
| 301 | const virtualizer = useVirtualizer({ |
| 302 | count, |
| 303 | getScrollElement: () => parentRef.current, |
| 304 | estimateSize: () => 45, |
| 305 | enabled, |
| 306 | onChange: (instance) => { |
| 307 | innerRef.current!.style.height = `${instance.getTotalSize()}px` |
| 308 | instance.getVirtualItems().forEach((virtualRow) => { |
| 309 | const rowRef = rowRefsMap.current.get(virtualRow.index) |
| 310 | if (!rowRef) return |
| 311 | rowRef.style.transform = `translateY(${virtualRow.start}px)` |
| 312 | }) |
| 313 | }, |
| 314 | }) |
| 315 | |
| 316 | const indexes = virtualizer.getVirtualIndexes() |
| 317 | |
| 318 | React.useEffect(() => { |
| 319 | virtualizer.measure() |
| 320 | }, []) |
| 321 | |
| 322 | return ( |
| 323 | <div> |
| 324 | <button |
| 325 | onClick={() => { |
| 326 | virtualizer.scrollToIndex(0) |
| 327 | }} |
| 328 | > |
| 329 | scroll to the top |
| 330 | </button> |
| 331 | <span style={{ padding: '0 4px' }} /> |
| 332 | <button |
| 333 | onClick={() => { |
| 334 | virtualizer.scrollToIndex(count / 2) |
| 335 | }} |
| 336 | > |
| 337 | scroll to the middle |
| 338 | </button> |
| 339 | <span style={{ padding: '0 4px' }} /> |
| 340 | <button |
| 341 | onClick={() => { |
| 342 | virtualizer.scrollToIndex(count - 1) |
| 343 | }} |
| 344 | > |
| 345 | scroll to the end |
| 346 | </button> |
| 347 | <span style={{ padding: '0 4px' }} /> |
| 348 | <button |
| 349 | onClick={() => { |
| 350 | setEnabled((prev) => !prev) |
nothing calls this directly
no test coverage detected