Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

How to promise the data before rendering in functional component React Native?

$
0
0

I'm new to React Native and developing an application. I wrote a code in which when user will press the login button then after successful login, through user's UID i'm getting an attribute of that specific user from Firebase Realtime Database. But when I'm testing it, I'm not getting anything. I have tried everything but nothing is working. may be its problem in my logic please help me out. I'm using latest version of React Native and Firebase.Thank you. This is my Code snippet for login button:

async function _loginBtnClick() {        setLoggedIn(true);        let valid = validate();        if(valid == 1){            setLoggedIn(false);            alert("Email and Password field should not be empty");        }        else if(valid == 2){            setLoggedIn(false);            alert("Email format is not correct. Please input a valid Email");        }        else if (valid == 3){            setLoggedIn(false);            alert("Password should contain at least 6 characters");        }        else if (valid == 4)        {            try {                    await auth().signInWithEmailAndPassword(email,password).then(()=>{                        setID(auth().currentUser.uid.toString());                        alert("ID is"+ id);                     });                    const ref = database().ref(`/users/${id}`);                    const snapshot =  await ref.once('value');                    let type = snapshot.val().userType;                    setUserType(type);                    _storeData(userType);                    setLoggedIn(false);                    navigation.reset({                        index: 0,                        routes: [{ name: 'customerDrawer' }],                    });            } catch (e) {                setLoggedIn(false);                alert(e);            }        }    }

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>