FirebaseExtended / FirebaseExtended/reactfire
useFirestoreCollection triggers a double render
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 403
- Avg merge
- 14h 53m
- Merged PRs (30d)
- 5
Description
Hi,
Seems like `useFirestoreCollection` always triggers unnecessary render when fetching data (suspense is **on**). Similar behavior is also the case for `useUser`.
There's a chance I'm simply using the API wrong, so please advise if so :)
### Version info
**React:** 17.0.2
**Firebase:** 9.1.3
**ReactFire:** 4.2.0
### Test case
```javascript
const q = /* whatever query */;
const queryResults = useFirestoreCollection(q);
console.log(queryResults);
```
### Expected behavior
`console.log` is called once.
### Actual behavior
`console.log` is called twice.
Ultimately, what I'm trying to achieve is a code similar to the one below
```javascript
const queryResults = useFirestoreCollection(query);
return queryResults.data.docs.map((d) => /* render */);
```
that renders only once when the data is fetched (and then only when there're changes in the collection).
Contributor guide
Research direction
Start by reproducing the behavior with the useFirestoreCollection test case and compare it with the similar useUser behavior. Inspect those hook entry points to determine why fetching with Suspense causes console.log to run twice. Done means fetching data produces one render, while later renders occur only when the collection changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- database, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100