Allow `useFirestoreDoc` `DocumentReference` arguments to be nullable
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- react, typescript
Hướng nghiên cứu
Bắt đầu từ entry point useFirestoreDoc và so sánh cách các đối số của nó hoạt động với hành vi nullable của useDocument được mô tả trong issue. Theo dõi cách kiểu DocumentReference của TypeScript được xử lý và kiểm tra các bài test Firestore hook hiện có. Được xem là hoàn tất khi các tham chiếu nullable được chấp nhận mà không có lỗi đường dẫn không hợp lệ, đồng thời hook vẫn hợp lệ khi được gọi vô điều kiện.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 3.6k
- Fork
- 403
- Merge trung bình
- 5 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 10
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FirebaseExtended/reactfire
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
FirebaseExtended/reactfire#801 ·
-
v5
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
FirebaseExtended/reactfire#793 ·
-
v5
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FirebaseExtended/reactfire#790 · 2 bình luận ·
-
v5
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
FirebaseExtended/reactfire#789 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
FirebaseExtended/reactfire#788 ·
Tất cả issue của FirebaseExtended/reactfire
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
bcgov/bc-wallet-mobile#4761 · 1 bình luận ·
-
external-issue to-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
area-deployment area-integrations triage:bot-seen
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 86/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100