Usage of useUser with useFirestoreDocData not very compatible within custom hooks
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- firebase, react, typescript
調査の方向性
まず、useUser、useFirestore、useFirestoreDocData のエントリーポイントを追跡し、issue に示されているカスタムフックを使って 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
- 平均マージ
- 5日 1時間
- マージ済み PR(30日)
- 10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
FirebaseExtended/reactfire のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 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 1週間以上 初心者へのやさしさ 35/100
FirebaseExtended/reactfire#788 ·
FirebaseExtended/reactfire の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
security
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
IBM/node-sdk-core#373 ·
-
e2e-failure ready-to-code
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
chore
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100