Skip to content

Commit

Permalink
fix(firestore): remove dynamic import from useCountFromServer (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
andipaetzold committed Nov 25, 2022
1 parent 70d9692 commit 47a03f6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ Returns:

Returns the number of documents in the result set of of a Firestore Query. Does not update the count once initially calculated.

Requires firebase 9.11.0 or later.

```javascript
const [count, loading, error] = useCountFromServer(query);
```
Expand Down
8 changes: 1 addition & 7 deletions src/firestore/useCountFromServer.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import type { FirestoreError, Query } from "firebase/firestore";
import { FirestoreError, Query, getCountFromServer } from "firebase/firestore";
import type { ValueHookResult } from "../common/types.js";
import { useOnce } from "../internal/useOnce.js";
import { isQueryEqual } from "./internal.js";

export type UseCountFromServerResult = ValueHookResult<number, FirestoreError>;

async function getData(stableQuery: Query<unknown>) {
const firestoreModule = await import("firebase/firestore");

const { getCountFromServer } = firestoreModule;

const snap = await getCountFromServer(stableQuery);
return snap.data().count;
}

/**
* Returns the number of documents in the result set of of a Firestore Query. Does not update the count once initially calculated.
*
* Requires firebase 9.11.0 or later
*
* @param {Query<unknown> | undefined | null} query Firestore query whose result set size is calculated
* @returns {UseCountFromServerResult} Size of the result set, loading state, and error
* * value: Size of the result set; `undefined` if the result set size is currently being calculated, or an error occurred
Expand Down

0 comments on commit 47a03f6

Please sign in to comment.