【发布时间】:2022-11-16 00:51:47
【问题描述】:
基本问题,但我一直在努力。
const GetDisplayName = async () => {
const docRef = doc(db, "userInfo", user.uid);
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
console.log(docSnap.get("fullname"));
const res = docSnap.get("fullname");
return <Text>{res}</Text>;
} else {
return <Text>hello</Text>;
}
};
无论我尝试什么,我都无法让 GetDisplayName 呈现。我什至尝试将 res 变量更改为纯字符串。我不断收到无效的对象作为反应子错误。
我的返回函数看起来像这样。如果两个都返回 JSX,为什么我的 Test 组件可以正常工作,但我的 GetDisplayName 组件不能正常工作?
const Test = () => <Text>"yooo</Text>;
//const docRef = doc(db, "userInfo", userID);
return (
<View>
<Text>Welcome Home!</Text>
<Test />
<GetDisplayName />
【问题讨论】:
标签: reactjs firebase react-native google-cloud-firestore jsx