Javascript 如何访问底部导航栏中类的this.state(React Native)

Javascript 如何访问底部导航栏中类的this.state(React Native),javascript,react-native,android-bottomnav,android-bottomappbar,Javascript,React Native,Android Bottomnav,Android Bottomappbar,我想在底部导航栏中访问MainAct类的这个.state。因此,当this.state更新导航栏时,会重新渲染 这是我的密码 我想访问底部导航栏“MainAct”中的“this.state.data”。(或任何替代方案) 是否将createMaterialBottomTabNavigator导出为默认值 //jshint忽略:开始 从“React”导入React,{Component}; 进口{ 看法 文本, 形象,, }从“反应本机”; window.navigator.userAgent=

我想在底部导航栏中访问MainAct类的这个.state。因此,当this.state更新导航栏时,会重新渲染

这是我的密码

我想访问底部导航栏“MainAct”中的“this.state.data”。(或任何替代方案)

是否将createMaterialBottomTabNavigator导出为默认值

//jshint忽略:开始
从“React”导入React,{Component};
进口{
看法
文本,
形象,,
}从“反应本机”;
window.navigator.userAgent='react native';
从“反应导航材料底部选项卡”导入{createMaterialBottomTabNavigator};
类MainAct扩展组件{
建造师(道具){
超级(道具);
此.state={
数据:“你好,世界”
}
}
render(){
返回(
{this.state.data}
);
}
}
导出默认createMaterialBottomTabNavigator({
屏幕1:{
屏幕:屏幕1,
导航选项:{
tabBarLabel:“屏幕1”,
tabBarIcon:({tintColor})=>(
)
}
},
屏幕2:{
屏幕:屏幕2,
导航选项:{
tabBarLabel:“屏幕2”,
tabBarIcon:({tintColor})=>(
)
}
},
屏幕3:{
屏幕:屏幕3,
导航选项:{
tabBarLabel:'Screen3',
tabBarIcon:({tintColor})=>(
)
}
},
主要行为:{
屏幕:MainAct,
导航选项:{
tabBarLabel:“MainAct”,
tabBarIcon:({tintColor})=>(
{this.state.data}
)
}
},
屏幕5:{
屏幕:屏幕5,
导航选项:{
tabBarLabel:'Screen5',
tabBarIcon:({tintColor})=>(
)
}
},
}, {
initialRouteName:“MainAct”,
activeColor:'#000000',
inactiveColor:“#000000”,
barStyle:{backgroundColor:'#FFFFFF',高度:60,标高:0,阴影颜色:0},

});如果您的
BottomNavigator
必须访问屏幕的状态,则您的状态可能位于错误的位置。你应该考虑为你的应用程序设置一个全局状态,因为React中的数据流应该是单向的,父组件不应该只访问子组件的状态

有多种方法可以做到这一点,如、、或任何您喜欢的状态管理库。如果您有全局状态,则
BottomNavigator
MainAct
都可以访问它