Memoize, lint

This commit is contained in:
Dan Abramov
2023-12-07 23:33:30 +00:00
parent a3a29556e9
commit 539e009bb8
3 changed files with 27 additions and 3 deletions
+1
View File
@@ -124,6 +124,7 @@ export function FeedsTabBar(
const styles = StyleSheet.create({
tabBar: {
// @ts-ignore web-only
position: isWeb ? 'fixed' : 'absolute',
zIndex: 1,
left: 0,
+25 -3
View File
@@ -139,9 +139,12 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
<View
style={[styles.contentContainer, contentContainerStyle, pal.border]}>
{(data as Array<ItemT>).map((item, index) => (
<View key={keyExtractor!(item, index)}>
{renderItem!({item, index, separators: null as any})}
</View>
<Row<ItemT>
key={keyExtractor!(item, index)}
item={item}
index={index}
renderItem={renderItem}
/>
))}
{onEndReached && (
<Tail threshold={onEndReachedThreshold} onVisible={onVisible} />
@@ -151,6 +154,25 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
)
})
let Row = function RowImpl<ItemT>({
item,
index,
renderItem,
}: {
item: ItemT
index: number
renderItem:
| null
| undefined
| ((data: {index: number; item: any; separators: any}) => React.ReactNode)
}): React.ReactNode {
if (!renderItem) {
return null
}
return renderItem({item, index, separators: null as any})
}
Row = React.memo(Row)
let Tail = ({
threshold = 0,
onVisible,
+1
View File
@@ -436,6 +436,7 @@ export function DesktopLeftNav() {
const styles = StyleSheet.create({
leftNav: {
// @ts-ignore web only
position: 'fixed',
top: 10,
// @ts-ignore web only