Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data Type definition

See original GitHub issue


I have been using your NPM package for a while now and I love it. Currently I am using Typescript + React Native for my project.

I came across a Type definition and wondert if was necessary.

const [values, loading, error] = useCollectionData<MyType[]>(ref);

In the line above I would expect values to be a type of: MyType[]. Instead it returned: values: Data<MyType[], "", "">[] | undefined

Is it a possibility to remove the wrapper?

Thank you, Bart

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

wolfibcommented, Jan 9, 2022

@chaosLegacy I just ran into a very similar issue: typing a firestore query required using a converter and as soon as I tried that I ran into an infinite loop.

What solved the problem for me was moving the definition of the converter out of the React component. I’m guessing that defining the converter in the component causes useIsFirestoreQueryEqual in the firestore hooks to believe it’s seeing a new query all the time and therefore triggering a rerender.

chaosLegacycommented, Dec 12, 2021

Hi, I’m new to firebase, and I found these hooks pretty much useful, but I have a little problem.

I’m using firebase ^9.6.1 along with react-firebase-hooks 4.0.1

This is the piece of code that I use to retreive my messages from firestore The type Post that i’ passing to useCollectionData seems generating an error: see below

    const messagesRef = collection(firestore, 'messages');
    const q = query(messagesRef, orderBy('createdAt'), limit(25));

    const [messages] = useCollectionData<Post[]>(q, { idField: 'id' });
Argument of type 'Query<DocumentData>' is not assignable to parameter of type 'Query<Post[]>'.
  Types of property 'converter' are incompatible.
    Type 'FirestoreDataConverter<DocumentData> | null' is not assignable to type 'FirestoreDataConverter<Post[]> | null'.
      Type 'FirestoreDataConverter<DocumentData>' is not assignable to type 'FirestoreDataConverter<Post[]>'.
        The types returned by 'fromFirestore(...)' are incompatible between these types.
          Type 'DocumentData' is not assignable to type 'Post[]'

Has anyone faced a similar issue? It seems that someone else had the same issue, it’s related to the fact that with firebase v9 defines its types, so it’s no longer possible to cast directly, instead use the built in FirebaseDataConverter

I did that

    const postConverter = {
        toFirestore(post: WithFieldValue<Post>): DocumentData {
            return { text: post.text, id: };
            snapshot: QueryDocumentSnapshot,
            options: SnapshotOptions
        ): Post {
            const data =!;
            return {
                id: data.idField,
                text: data.text,
                uid: data.uid

and I hooked it to my query

    const messagesRef = collection(firestore, 'messages');
        const q = query(messagesRef, orderBy('createdAt'), limit(25)).withConverter(postConverter); // <---- here

    const [messages] = useCollectionData<Post[]>(q, { idField: 'id' });

Now I get an infinite loop in my code saying:

Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.

Am I doing something wrong ? 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is data type? | Definition from TechTarget
A data type, in programming, is a classification that specifies which type of value a variable has and what type of mathematical, relational...
Read more >
Data type - Wikipedia
In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allowed...
Read more >
What Are Data Types and Why Are They Important? - Amplitude
A data type is an attribute associated with a piece of data that tells a computer system how to interpret its value.
Read more >
Data Types – Programming Fundamentals - Rebus Press
A data type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. Most...
Read more >
10 Data Types (With Definitions and Examples) |
A data type is an attribute of a piece of data that tells a device how the end-user might interact with the data....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found