问题描述
App.js
export default class App extends React.Component {
render() {
return (
<NavigationContainer>
<Drawer.Navigator
drawerContent={(props) => <DrawerContent {...props} />
<Drawer.Screen name="Home" component={MainTabscreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}
}
Login.js
export default class Login extends React.Component {
constructor(props) {
super(props);
this.state = {
email: '',password: '',bob: '',};
}
onLogin = () => {
let userDetails = require('../api.json');
const {email,password} = this.state;
try {
let loginDetails = userDetails.users.find(
(el) => el.email && el.password,);
if (email == loginDetails.email && password == loginDetails.password)
bob = loginDetails.phoneNumber;
this.setState({
bob: bob,});
this.props.navigation.navigate('Home');
} catch (error) {
alert('Enter Correct Username and Password');
}
};
抽屉内容
export function DrawerContent({...props}) {
return (
<View style={{flex: 1}}>
<DrawerContentScrollView {...props}>
<View style={{backgroundColor: 'white'}}>
</View>
<View style={{flexDirection: 'row',marginTop: 20,paddingLeft: 7}}>
<View style={{marginLeft: 15,flexDirection: 'column'}}>
<Title style={styles.title}>{** I need to get the value of state 'bob' here from Login.js ** }</Title>
</View>
</View>
在启动应用程序时,它显示为“找不到变量:bob”,但是当我在应用程序中时,如果我尝试获取变量,我可以获得我想要的值。 在过去的一周里,我正在尝试对此进行调试。
我是 React-native 的初学者
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)