Allow `useFirestoreDoc` `DocumentReference` arguments to be nullable
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 52/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 冷清
- 技術堆疊
- react, typescript
研究方向
從 useFirestoreDoc 入口點開始,將其參數行為與 issue 中描述的 nullable useDocument 行為進行比較。追蹤 TypeScript DocumentReference 型別的處理方式,並檢查現有的 Firestore hook 測試。完成的標準是:nullable 參照可以被接受而不會產生無效路徑錯誤,且該 hook 在無條件呼叫時仍保持有效。
由索引模型根據 Issue 內容生成。
描述
react-firebase-hooks allows the document reference to useDocument to be nullable and just returns undefined if it is. This was useful for paths relying on nullable info, like auth.currentUser.uid:
const [snapshot, loading, error] = useDocument(auth.currentUser && firestore.doc(`users/${auth.currentUser.uid}`));
where if the user were not signed in there wouldn't be an error thrown since useDocument would just return undefined. It would be nice if a similar feature were added to reactfire, as
const { status, data: firebaseDoc } = useFirestoreDoc(auth.currentUser && doc(firestore, 'users', auth.currentUser.uid));
won't work as the type of ref is DocumentReference, not DocumentReference | null,
const { status, data: firebaseDoc } = useFirestoreDoc(doc(firestore, 'users', auth.currentUser?.uid));
will throw an error when the user is not signed in (as the path will become invalid), and
if (auth.currentUser) {
const { status, data: firebaseDoc } = useFirestoreDoc(doc(firestore, 'users', auth.currentUser.uid));
}
violates the rules of hooks.
Currently relying on a rather abhorrent workaround to resolve this and it would be ideal if reactfire could support this behavior natively.
- 主要語言
- TypeScript
- 星號
- 3.6k
- 分支
- 403
- 平均合併
- 5 天 1 小時
- 30 天內合併 PR
- 10
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
FirebaseExtended/reactfire 的其他 Issue
-
難度 5/5 一週以上 新手友好度 38/100
FirebaseExtended/reactfire#801 ·
-
v5
難度 4/5 3-5 天 新手友好度 48/100
FirebaseExtended/reactfire#793 ·
-
v5
難度 4/5 3-5 天 新手友好度 35/100
FirebaseExtended/reactfire#790 · 2 則留言 ·
-
v5
難度 4/5 3-5 天 新手友好度 55/100
FirebaseExtended/reactfire#789 ·
-
難度 5/5 一週以上 新手友好度 35/100
FirebaseExtended/reactfire#788 ·
查看 FirebaseExtended/reactfire 的全部 Issue
相似的 Issue
-
resources
難度 2/5 1-3 小時 新手友好度 72/100
railmapgen/rmg-palette#2445 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
danielmiessler/LifeOS#2242 ·
維護者通常 5 天內回覆
-
good first issue hacktoberfest help wanted translation
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
callstackincubator/appduct#129 ·
維護者通常 1 天內回覆
-
難度 1/5 1-3 小時 新手友好度 88/100