我是 React Native 开发的新手,在将 props 传递给 tabNavigator 时遇到了麻烦。我想将我的 Home 组件中的 deconnect 函数传递给在 tabNavigator 中调用的配置文件组件。 这是我的主页组件
export default class Home extends React.Component{
constructor(props){
super(props);
}
render(){
return(
<TabNavigator deconnect={this.props.deconnect}/>
);
}}
这是我的 tabNavigator :
const TabNavigator = createMaterialBottomTabNavigator(
{
Profil: {
screen: ProfileScreen,
navigationOptions: {
tabBarLabel: 'Profil',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon2
style={[{ color: tintColor }]} size={25} name={'user'} />
</View>
),
},
},
},
{
initialRouteName: 'Livraisons',
activeColor: '#226557',
inactiveColor: '#9E9E9E',
barStyle: { backgroundColor: '#c0dfef' },
}
);
导出默认 createAppContainer(TabNavigator);
这是一个非工作代码,让您知道我想做什么:
const TabNavigator = createMaterialBottomTabNavigator(
{
Profil: {
screen: <ProfileScreen deconnect={this.props.deconnect} />,
navigationOptions: {
tabBarLabel: 'Profil',
tabBarIcon: ({ tintColor }) => (
<View>
<Icon2
style={[{ color: tintColor }]} size={25} name={'user'} />
</View>
),
},
},