Skip to content

Conversation

@HassanBahati
Copy link
Member

This PR adds useGetCountFromServerQuery hook

@docs-page
Copy link

docs-page bot commented Sep 26, 2024

To view this pull requests documentation preview, visit the following URL:

react-query-firebase.invertase.dev/~105

Documentation is deployed and generated using docs.page.

...options,
queryFn: async () => {
const snapshot = await getCountFromServer(query);
return snapshot?.data().count;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why would the snapshot here ever be nullish? From the API docs it should always return a snapshot: https://firebase.google.com/docs/reference/js/firestore_.md#getcountfromserver_4e56953

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, ive actually removed the optional chaining

...options,
queryFn: async () => {
const snapshot = await getCountFromServer(query);
return snapshot.data().count;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be returning the snapshot here or the count?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be returning the snapshot.

ive refactored to return an AggregateQuerySnapshot which is described as the return type of the getCountFromServer


await waitFor(() => expect(result.current.isSuccess).toBe(true));

expect(result.current.data?.data().count).toBe(3);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is optional chaining at data?.data() because useQuery initializes with undefined data before the query resolves
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's OK, it's because typescript isn't inferring isSuccess with data (since it's inside of waitFor).

@HassanBahati HassanBahati requested a review from Ehesp September 29, 2024 18:42
@Ehesp Ehesp merged commit 84d67f4 into invertase:next Sep 30, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants