Migration to v3
Version 3 introduces first‑class Web support and a new SectionList component, plus several API improvements.
✨ New in v3
Web Support
- DOM‑native rendering (no React Native dependency required)
- Same virtualization core as React Native
- Web examples and docs
SectionList Component
@legendapp/list/section-listwith a React Native‑compatible APIscrollToLocationsupport- Sticky section headers powered by
stickyHeaderIndices
Always Render
alwaysRenderkeeps selected items mounted outside the virtualization window
Better Scroll & Metrics APIs
initialScrollAtEndfor chat and feedsanchoredEndSpacefor reserving readable space after a chat or feed anchor rowcontentInsetEndAdjustmentfor floating composers and overlay UI at the end of a listuseKeyboardChatComposerInsetfor React Native keyboard chat composersonMetricsChangefor header/footer size changesgetState()now exposes listeners, element access, and scroll velocity
🔄 Breaking changes from v2
-
Typed import paths
- The root
@legendapp/listcomponent export has been removed in v3. - Use:
- React Native:
@legendapp/list/react-native - React (Web):
@legendapp/list/react
- React Native:
- The root
-
maintainVisibleContentPositiondefaults- v3 now enables scroll-position stabilization on size changes by default
- Default behavior is equivalent to
maintainVisibleContentPosition={{ size: true, data: false }} - Toggle specific behavior as needed:
maintainVisibleContentPosition={{ data: true }}to anchor on data changes toomaintainVisibleContentPosition={{ size: false }}to disable size/layout stabilizationmaintainVisibleContentPosition={true}to enable bothsizeanddatamaintainVisibleContentPosition={false}to disable both
-
Size hints and fixed-size callbacks
getFixedItemSizeis now(item, index, type)getEstimatedItemSizehas been removed. Prefer no estimate for most dynamic-size lists,estimatedItemSizeonly as a small initial allocation hint when rows are far from100px, orgetFixedItemSizewhen sizes are known exactly.suggestEstimatedItemSizehas been removed. Useref.current?.getState().getAverageItemSizes()to inspect measured average sizes directly.
-
Sticky headers prop rename
stickyIndiceshas been removed. UsestickyHeaderIndices.
-
Keyboard integration entrypoint update
- v2 keyboard docs used
@legendapp/list/keyboard-controllerandLegendList. - In v3 use
@legendapp/list/keyboardand importKeyboardAwareLegendList. LegendListis no longer exported from the@legendapp/list/keyboardentrypoint.- Chat screens can use
KeyboardAwareLegendList,useKeyboardScrollToEnd, anduseKeyboardChatComposerInsetfrom@legendapp/list/keyboard. KeyboardAvoidingLegendListis available from@legendapp/list/keyboard-legacyfor apps that still need the previous keyboard-avoiding integration.
- v2 keyboard docs used
-
renderItemis a render callbackrenderItemis called directly as(props) => ReactNode.- Do not pass a hook-using item component directly as
renderItem={Row}. - Return hook-using item components from the callback instead:
renderItem={({ item }) => <Row item={item} />}.
-
Imperative scroll methods are async
- These ref methods now return
Promise<void>:scrollIndexIntoViewscrollItemIntoViewscrollToEndscrollToIndexscrollToItemscrollToOffset
- If you run logic after a programmatic scroll,
awaitthe call.
- These ref methods now return
-
getState()shape changed for advanced integrationsstate.positionsis no longer part of the publicgetState()return value.- Replace direct map access with:
positionAtIndex(index)positionByKey(key)
getState()now also exposes listener helpers (listen,listenToPosition),scrollVelocity, andgetAverageItemSizes().
-
Removed compatibility props and types
initialContainerPoolRatiohas been removed. LegendList manages spare container capacity automatically.InitialScrollAnchorhas been removed. UseScrollIndexWithOffsetPositionfor public initial-scroll position typing.
Migration checklist
- Move imports to typed platform entrypoints (
/react-nativeor/react) - Update fixed-size callback signatures to
(item, index, type) - Replace
getEstimatedItemSizewith no estimate,estimatedItemSizeonly for unusual initial sizes, orgetFixedItemSize - Replace
suggestEstimatedItemSizewithgetState().getAverageItemSizes() - Replace
stickyIndiceswithstickyHeaderIndices - Remove
initialContainerPoolRatio; spare container capacity is automatic - Replace
InitialScrollAnchortype references withScrollIndexWithOffsetPosition - Update keyboard imports from
@legendapp/list/keyboard-controllerto@legendapp/list/keyboardand useKeyboardAwareLegendList - If you still need the previous keyboard-avoiding integration, import
KeyboardAvoidingLegendListfrom@legendapp/list/keyboard-legacy - Wrap hook-using item components in a
renderItemcallback instead of passing them directly - For floating composers, replace content padding workarounds with
contentInsetEndAdjustmenton web oruseKeyboardChatComposerInsetwithKeyboardAwareLegendListon React Native awaitimperative scroll calls if your code depends on post-scroll timing- Update advanced
getState()consumers to usepositionAtIndex/positionByKeyinstead ofpositions
Install
npm install @legendapp/list