Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Usage of useUser with useFirestoreDocData not very compatible within custom hooks

Đang mở
#423 4 bình luận 5 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
firebase, react, typescript

Hướng nghiên cứu

Bắt đầu bằng cách lần theo các entry point useUser, useFirestore và useFirestoreDocData, rồi tái hiện nhánh null-user bằng custom hook được nêu trong issue. So sánh hành vi được báo cáo của ReactFire v4 với hành vi của ReactFire v3 được tham chiếu trong issue 249; issue không nêu tên file, test hay tiêu chí hoàn thành cụ thể nào.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

v5
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

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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của FirebaseExtended/reactfire

Tất cả issue của FirebaseExtended/reactfire

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.