I am fetching data from Cloud Firestore with this code
const [profile, setProfile] = useState({});
useEffect(() => {
const fetchDoc = async() => {
const response = await db.collection("users").doc(id).get();
const data = response.data();
setProfile({...data});
}
fetchDoc();
}, []);
This saves an object to the state that looks like this
{
name: 'sample name',
tertiary: {
name: ['sample 1', 'sample 2', ...]
},
...
}
The first time the page mounts, console.log(profile) returns an empty object. But then, as from what I know, useEffect triggers after this mounting, and fetches the data. Afterwards, console.log(profile) now returns the object fetched.
Now, for some reason, when I pass profile.tertiary.name as props to a component, I get an error that says it is undefined. This happens every time the page first mounts, and useEffect doesn't do anything afterwards.
<CustomBioList education={profile.tertiary.name} />
In the <CustomBioList /> component, I'm simpy trying to console.log(props) to check whether it gets the data. Am I fetching the data in a wrong way? I don't grasp the full concept of useEffect.