Если вы говорите об этом коде:
Authentication.firestore().collection('Health_data')
.doc(localStorage.getItem('user'))
.get()
.then(doc => {
const data = doc.data();
localStorage.setItem('user_data', JSON.stringify(data));
setuserData(data)
console.log(data)
}).catch(function (error) {
console.error("Error reading health", error);
});
console.log(userData)
Проблема в
Authentication.firestore().collection('Health_data')
.doc(localStorage.getItem('user'))
.get()
Это асинхронное c выполнение, поэтому console.log(userData)
иногда будет выполняться перед Authentication
вызов и значение будет null
.
Таким образом, вы должны убедиться, что вызов Authentication
завершен