I am trying to get data from userRef and use it to make another async call to another doc (eg: bikes) and then render that bikes doc on the page
Right now in the Home screen function the userDetailslog prints {"_U": 0, "_V": 0, "_W": null, "_X": null}. Which im assuming is because its being fired before the data is returned.
ideas on how i can structure it better to get appropriate data printed into HomeScreen?
Any help is appreciated
const userData = async () => {
const user = auth().currentUser;
var userRef = firestore().collection('users').doc(user.uid);
try {
var doc = await userRef.get();
if (doc.exists) {
console.log(doc.data()); // Prints Perfectly
return doc.data();
} else {
console.log('No such document!');
}
} catch (error) {
console.log('Error getting document:', error);
}
};
const HomeScreen = () => {
const userDetails = userData(); //
useEffect(() => {
console.log(userDetails); // Doesn't print here
}, [userDetails]);
const navigation = useNavigation();
return (
<View>
<Text>Home Screen</Text>
<Button title="logout" onPress={logout} />
</View>
);
};
then, in order to get the data inside.