I'm trying to access the data inside of my user object in my firestore databases. However, I keep getting promises instead of the objects.
function StorefrontPage(props) {
const auth = useAuth();
const router = useRouter();
const [user, setUser] = useState({});
const uid = auth.user && auth.user.uid;
useEffect(() => { uid && getUser(uid, setUser);
console.log(user);
}, [])
console.log(user);
The first time I run this, it returns the objects I want, but subsequent refreshes and page changes will turn the console.log into a proto object/promise. I thought wrapping it inside of the useEffect hook would solve this issue, but it is not. How do I make sure it always returns the user object instead of a promise?
For reference, the getUser function is:
export function getUser2(uid, setUser) {
return firestore.collection('users')
.doc(uid).get()
.then(user => setUser(user))
.catch(err => console.log(err));
}