Repository navigation
Replies: 1 comment
|
Confirmed against source (main @ 8beb228, ahead of the published 3.3.8): row content is memoized per container with dependencies
It appears intentional, and On whether the list could detect a meaningful What works today:
A related datapoint consistent with this mechanism: #271 (closed) reported focus loss specifically when Caveat: verified against |
Uh oh!
There was an error while loading. Please reload this page.
Something like this works fine in FlatList and FlashList, but results in stale UI in LegendList:
When
renderItemchanges - for example because theselectedIdstate it closes over changes, or because we've disabled the react compiler so it's recreated on each render -LegendListdoes not re-render its items. So the selected item never seems to change.Just curious if this is intentional behaviour or not?
I think the situation is a bit confusing because the
FlatListdocs use this exact example to teach you to use theextraDataprop, but it's actually completely unnecessary. (See 2nd example at https://reactnative.dev/docs/flatlist#example and its surrounding text.) In bothFlatListandFlashListyou can removeextraDataand it works fine. But inLegendListyou need to addextraData={isSelected}, or change how/where the state is stored.If it is intentional then fair enough :-) I doubt there's any way to tell from within
LegendListwhetherrenderItemhas changed meaningfully or not. So I guess you'd have to rely on the compiler memoizing it, or the user wrapping it inuseCallbackwith the correct dependency array - which I appreciate could tank performance for many users!Demo: https://github.com/mdj-uk/legend-list-closure-demo
(Aside: is there a way to share a demo with expo snack? When I try there's an error message saying "This package cannot be bundled for the Snack runtime because it depends on modules that are unavailable in the browser or on native platforms")
All reactions