# Version 2

Version 2 — Legend List documentation.

Source: https://legend.so/list/v2/version-2/

Legend List v2 documentation. **Archived version.** [Read the current documentation.](https://legend.so/list/v3/overview/)

Version 2 is faster, more accurate, and smaller. There are no breaking changes, but it's almost a full rewrite, so we're calling it a major version!

This update is primarily focused on accuracy and performance. The `maintainVisibleContentPosition` algorithm was rewritten in a way that's much more accurate and performant, and also allowed us to remove a ton of hacks, workarounds, and lots of management code.

The new simpler implementation of `maintainVisibleContentPosition` enabled new features like sticky headers.

Many features were added to support advanced customization and behaviors for complex lists like AI chats.

## [Install the update](https://legend.so/list/v2/version-2/#install-the-update)

```bash
npm install @legendapp/list@2
```

## [🎉 Major Improvements](https://legend.so/list/v2/version-2/#-major-improvements)

### [Accuracy](https://legend.so/list/v2/version-2/#accuracy)

-   Perfectly accurate `initialScrollIndex`, `scrollToIndex`, and `scrollToEnd`
-   Bidirectional infinite scroll never has any flashing or jumpiness
-   Uses average sizes after the first render so `estimatedItemSize` is now optional

### [Scroll Performance](https://legend.so/list/v2/version-2/#scroll-performance)

-   `maintainVisibleContentPosition` is so much better and faster that it's now enabled by default
-   Reduced number/size of renders while updating positions
-   Improved container recycling to reuse containers more efficiently

## [✨ New Features](https://legend.so/list/v2/version-2/#-new-features)

### [Sticky Headers](https://legend.so/list/v2/version-2/#sticky-headers)

-   `stickyIndices` prop for creating sticky headers that remain visible while scrolling

### [Enhanced Item Type System](https://legend.so/list/v2/version-2/#enhanced-item-type-system)

-   `getItemType` prop allows categorizing different item types for better performance optimization
-   `getFixedItemSize` prop for items with known fixed sizes, enabling performance optimizations
-   `renderItem`, `getFixedItemSize`, and `getEstimatedItemSize` functions now receive an item type parameter

### [Lazy List](https://legend.so/list/v2/version-2/#lazy-list)

-   Built-in lazy list support directly in the `LegendList` component

### [Scroll Position Management](https://legend.so/list/v2/version-2/#scroll-position-management)

-   `snapToIndices` prop for snapping scroll position to specific item indices
-   `maintainVisibleContentPosition` is now enabled by default for better scroll stability

### [Advanced Hooks and References](https://legend.so/list/v2/version-2/#advanced-hooks-and-references)

-   `useSyncLayout` hook for synchronizing layout operations
-   Ref function to enable/disable scroll processing for advanced use cases
-   `getState()` now includes `positionAtIndex` and `data` for debugging and advanced integrations

### [Code Quality](https://legend.so/list/v2/version-2/#code-quality)

-   Extracted most functionality into small, testable functions
-   Added extensive test infrastructure

## [🔄 Migration Guide](https://legend.so/list/v2/version-2/#-migration-guide)

### [From v1 to v2](https://legend.so/list/v2/version-2/#from-v1-to-v2)

Most v2 changes are backward compatible, but note this one change:

1.  `maintainVisibleContentPosition` now defaults to `true`. It has no significant overhead so it should be fine to leave it enabled. It's required for accurate `initialScrollIndex`, `scrollToIndex`, and infinite scrolling up.

[View Markdown](https://legend.so/list/v2/version-2.md)[Report a documentation correction](https://github.com/LegendApp/legend-docs/issues/new?title=Docs%3A+Version+2&body=Page%3A+https%3A%2F%2Flegend.so%2Flist%2Fv2%2Fversion-2%0A%0AWhat+is+incorrect+or+missing%3F%0A%0AExpected+behavior+or+supporting+source%3A%0A)
