Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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');
    }
  };



   

drawer content

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>

        
      

while launching the app it shows like "can't find variable: bob" but when I was in the app and then if I try to get the variable I can able to get the value that I wanted. I am trying to debug this for the past week.

And I am a beginner to React-native


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
598 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...