-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Firestore] Include typescript intersection type for idField option on all use...Data hooks #50
Comments
Totally agree with @cdoe . export default function useSnapshot<T>(query?: firestore.Query | null | undefined, options?: {
snapshotListenOptions?: firestore.SnapshotListenOptions | undefined;
} | undefined): [IGeneric<T>[] | undefined, firestore.QuerySnapshot | undefined, boolean, Error | undefined] {
const [value, loading, error] = useCollection(query, options)
const model = value && value.docs.map(val => {
const data = val.data() as T
const model: IGeneric<T> = {
uid: val.id,
data
}
return model
})
return [model, value, loading, error];
` |
+1 This should definitely be in there. Does anyone have any idea how to achieve this? |
I've just been having a play around with this and have got something working which will be part of the upcoming v3 of the library. I'm aiming to have this released in the next week or 2. For reference, the syntax is:
|
This has now been released in https://github.com/CSFrequency/react-firebase-hooks/releases/tag/v3.0.1 |
For Firestore collections and docs, it would be nice if each of the
...Data
hooks would automatically add theidField
(if provided) as a key/value to the<T>
generic.For example, the
useDocumentData
hook would return something likeT & { idField: string }
instead of justT
. In this case,idField
should be represented by the actual string value entered intooptions.idField
.Does this make sense? I feel like it should be trivial to do something like this, but couldn't quite get it to work myself. I'd be happy to make a pull request if anyone has some extra insight.
Thanks!
The text was updated successfully, but these errors were encountered: