Skip to content

Commit 1e0c873

Browse files
authored
Merge pull request #851 from thundersdata-frontend/rn-issue
fix: 修复Tabs在涉及到state变动时导致re-render的bug
2 parents b6c886c + b1257f7 commit 1e0c873

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

.changeset/small-years-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@td-design/react-native-tabs': patch
3+
---
4+
5+
fix: 修复Tabs在涉及到state变动时导致re-render的bug

packages/react-native-tabs/src/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ComponentType, createElement, memo } from 'react';
1+
import React, { ReactNode } from 'react';
22
import { Animated, StyleProp, TextStyle, ViewStyle } from 'react-native';
33
import PagerView from 'react-native-pager-view';
44

@@ -14,7 +14,7 @@ const AnimatedPagerView = Animated.createAnimatedComponent<typeof PagerView>(Pag
1414

1515
type Tab = {
1616
title: string;
17-
component: ComponentType<any>;
17+
component: ReactNode;
1818
};
1919

2020
export interface TabsProps {
@@ -113,15 +113,11 @@ export default function Tabs({
113113
{({ loading }) => {
114114
if (loading) return renderLazyPlaceholder?.();
115115

116-
return <SceneComponent {...{ component }} />;
116+
return component;
117117
}}
118118
</SceneView>
119119
))}
120120
</AnimatedPagerView>
121121
</Box>
122122
);
123123
}
124-
125-
const SceneComponent = memo(<T extends { component: ComponentType<any> }>({ component }: T) => {
126-
return createElement(component);
127-
});

0 commit comments

Comments
 (0)