Usage of useUser with useFirestoreDocData not very compatible within custom hooks
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
- Issue 類型
- 功能
- 描述清晰度
- 需要釐清
- 活躍度
- 停滯
- 技術堆疊
- firebase, react, typescript
研究方向
先追蹤 useUser、useFirestore 和 useFirestoreDocData 這些進入點,並使用 issue 中顯示的自訂 hook 重現 null-user 路徑。將回報的 ReactFire v4 行為與 issue 249 中參照的 ReactFire v3 行為進行比較;該 issue 未指出檔案、測試或具體的完成條件。
由索引模型根據 Issue 內容生成。
描述
Version info
React: 18 experimental
Firebase: 9
ReactFire: 4
Other (e.g. Node, browser, operating system) (if applicable):
Test case
Steps to reproduce
const useMyHook= () => {
const firestore = useFirestore();
const {data: user} = useUser();
const ref = user && doc(firestore, "users", user.uid);
const {data: userData} = useFirestoreDocData(ref);
return userData;
}
Behavior
Since useUser is returning the type User | null , we need to check, if the user is available. But in the case when the user is null, useFirestoreDocData cannot be called, since the ref would not exist. In react we are not allowed to write:
const {data: userData} = ref && useFirestoreDocData(ref)
One way to get around this issue is by passing in the user as a prop, but it does not seem to be convenient, if one wants to use this hook within another hook. We would just push the issue upwards until we reach a component that is again wrapped by a component that knows if the user exists:
- component that checks if user exists (like deprecated AuthCheck)
- component that is rendered when user exists
- hook that is called within that component
Another alternative for typescript is writing user! with exclamation mark, but this does not feel proper.
I hope the case is clear and you might know a better way to deal with it.
I think with react-fire v3 (fb v8) I wasn't experiencing this issue. Since it was probably solved with this issue: https://github.com/FirebaseExtended/reactfire/issues/249
- 主要語言
- TypeScript
- 星號
- 3.6k
- 分支
- 403
- 平均合併
- 4 天 19 小時
- 30 天內合併 PR
- 11
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
FirebaseExtended/reactfire 的其他 Issue
-
難度 5/5 一週以上 新手友好度 38/100
FirebaseExtended/reactfire#801 ·
維護者通常 2 天內回覆
-
v5
難度 4/5 3-5 天 新手友好度 48/100
FirebaseExtended/reactfire#793 ·
維護者通常 2 天內回覆
-
v5
難度 4/5 3-5 天 新手友好度 35/100
FirebaseExtended/reactfire#790 · 2 則留言 ·
維護者通常 2 天內回覆
-
v5
難度 4/5 3-5 天 新手友好度 55/100
FirebaseExtended/reactfire#789 ·
維護者通常 2 天內回覆
-
難度 5/5 一週以上 新手友好度 35/100
FirebaseExtended/reactfire#788 ·
維護者通常 2 天內回覆
查看 FirebaseExtended/reactfire 的全部 Issue
相似的 Issue
-
area/core status/need-triage
難度 2/5 1-3 小時 新手友好度 88/100
google-gemini/gemini-cli#29602 ·
維護者通常 1 天內回覆
-
area: backend enhancement priority: low
難度 2/5 1-3 小時 新手友好度 88/100
snapotter-hq/SnapOtter#1879 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 86/100
Tencent/BrowserSkill#390 ·
維護者通常 1 天內回覆
-
good first issue status: needs triaging type: bug version: 2.0
難度 2/5 1-3 小時 新手友好度 85/100
medusajs/medusa#17094 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 1 天內回覆