【发布时间】:2020-06-20 12:16:45
【问题描述】:
我正在开发一个应用程序,我正在使用bottomTabNavigator,但同时我收到了这个警告! ( Look like you're passing an inline function for 'Component' prop for the screen 'Feed' (e.g component={()=><SomeComponent/>)). Passing an inline function will cause the component state to be lost on re-render and cause perf issue since it's re-created every render. You can pass the function as children to 'Screen' instead to achieve the desired behaviour.
我知道我做错了什么,但我没有弄清楚我的代码有什么问题。我是 React Native 的新手,谁能帮我解决这个警告。
代码
return (
<NavigationContainer>
<Tab.Navigator
initialRouteName="Home"
tabBarOptions={{
activeTintColor: "#e91e63"
}}
>
<Tab.Screen
name="Home"
component={props => (
<PharmacyHome
catId={this.props.navigation.state.params}
{...props}
/>
)}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={color} size={size} />
)
}}
/>
<Tab.Screen
name="Notifications"
component={Notifications}
options={{
tabBarLabel: "Updates",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="bell" color={color} size={size} />
)
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: "Profile",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons
name="account"
color={color}
size={size}
/>
)
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
【问题讨论】:
-
对于从谷歌搜索访问此页面的任何其他人:如果您将屏幕命名为“组件”,即使在其自己的源文件中,也会出现错误消息,例如:“ const component = (props) => { .. }; 导出默认组件; ".这是因为 react-navigation 代码实际上会检查组件的名称是否为“组件”。见这里:github.com/react-navigation/react-navigation/blob/master/…
标签: javascript reactjs react-native ecmascript-6