Skip to content

Commit 81a807a

Browse files
authored
Merge pull request #19 from cmmartin/patch-1
Return null instead of empty object when document doesn't exist
2 parents a82e2c0 + 0f2980d commit 81a807a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

firestore/helpers/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { firestore } from 'firebase';
33
export const snapshotToData = (
44
snapshot: firestore.DocumentSnapshot,
55
idField?: string
6-
) => ({
7-
...snapshot.data(),
8-
...(idField ? { [idField]: snapshot.id } : null),
9-
});
6+
) => {
7+
if (!snapshot.exists) return null;
8+
return {
9+
...snapshot.data(),
10+
...(idField ? { [idField]: snapshot.id } : null),
11+
};
12+
};

0 commit comments

Comments
 (0)