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({ const styles = StyleSheet.create({
tabBar: { tabBar: {
// @ts-ignore web-only
position: isWeb ? 'fixed' : 'absolute', position: isWeb ? 'fixed' : 'absolute',
zIndex: 1, zIndex: 1,
left: 0, left: 0,
+25 -3
View File
@@ -139,9 +139,12 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
<View <View
style={[styles.contentContainer, contentContainerStyle, pal.border]}> style={[styles.contentContainer, contentContainerStyle, pal.border]}>
{(data as Array<ItemT>).map((item, index) => ( {(data as Array<ItemT>).map((item, index) => (
<View key={keyExtractor!(item, index)}> <Row<ItemT>
{renderItem!({item, index, separators: null as any})} key={keyExtractor!(item, index)}
</View> item={item}
index={index}
renderItem={renderItem}
/>
))} ))}
{onEndReached && ( {onEndReached && (
<Tail threshold={onEndReachedThreshold} onVisible={onVisible} /> <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 = ({ let Tail = ({
threshold = 0, threshold = 0,
onVisible, onVisible,
+1
View File
@@ -436,6 +436,7 @@ export function DesktopLeftNav() {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
leftNav: { leftNav: {
// @ts-ignore web only
position: 'fixed', position: 'fixed',
top: 10, top: 10,
// @ts-ignore web only // @ts-ignore web only