Get current users data from Firestore on ReactJS using uid as a link between the user auth and Firestore. Get this error: Too many re-renders
I am trying to get user data from Firestore using UID to link the Firestore data and the user auth. I have tried this but keep getting a blank screen with too many re-renders errors. Would anyone be able to help?
My Firestore collection is named values and it stores Fname,Lname, bio, username and uid.
import React, { Component, useState, useEffect } from 'react';
import {
StyleSheet,
Text,
View,
Image,
} from 'react-native';
import { auth, db } from '../Firebase'
const UserProfileView = () => {
const [user, setUser] = useState();
const {uid} = auth.currentUser.uid;
const userRef = db.collection('values').doc(uid);
const doc = userRef.get();
doc.data;
const userData = doc.data;
setUser(userData);
// Get user on mount
useEffect(() => {
UserProfileView();
}, []);
//adapted from https://www.bootdey.com/react-native-snippet/12/User-profile-with-options
My return the only code that relates to the above is the text tag with user && user?.Fname.
return (
{auth.currentUser?.uid}
{user && user?.Fname}
{auth.currentUser?.email}
Florida
Home
Settings
News
Shop
);
}
export default UserProfileView;