Skip to content

Request: add generics to mirror firestore and improve type safety #67

@ehahn9

Description

@ehahn9

react-firebase-hooks rocks, btw -- thanks!

slight (trivial) suggestion:

// current
export const useDocument = (
  docRef?: firestore.DocumentReference | null,

// proposed
export const useDocument<T = firestore.DocumentData> = (
  docRef?: firestore.DocumentReference<T> | null,

this would also apply to useCollection, etc.

This would be helpful because firestore does indeed preserve the type all the way to the subsequent snapshot data() value.

As a side-benefit, a typed ref would improve the useDocumentData API allowing you to deduce the returned data type without the explicit generic:

// current
const [data, loading, error] = useDocumentData<MyData>(ref);

// becomes (optional, if your ref happens to be typed)
const [data, loading, error] = useDocumentData(myDataRef); // myDataRef is DocumentReference<MyData>

ps: best practice would still be to validate the payload with yup etc. but this would go a long way!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions