CSFrequency / react-firebase-hooks

React Hooks for Firebase.
Apache License 2.0
3.58k stars 304 forks source link

feat: add id to useCollectionData and useCollectionDataOnce hooks #267

Closed VicenteMerino closed 1 year ago

VicenteMerino commented 2 years ago

Would be useful to have the id in the useCollectionData and useCollectionDataOnce hooks, specially to filter among different documents. Maybe it could also be one of the parametes if it must be included i'll do it.

philippotto commented 1 year ago

I found your PR while researching how to access the IDs while using the useCollectionData hook. You might want to have a look at the docs here which was the solution for me in the end. That approach also works well with type safety and avoids that you accidentally add an additional id field to your documents.

mauriceackel commented 1 year ago

Hey @VicenteMerino, I believe what @philippotto shared is the way to go in the future! This library formerly had an option to also store the document id but is was removed in favour of data transformers.

I believe it's cool that you created this PR but given that the decision against an explicit id was already made, it might be best if you close this PR :) Thanks!

chrisbianca commented 1 year ago

@VicenteMerino As per the comments from @philippotto and @mauriceackel, we made the switch in v5 to use data transformers as this is the recommended approach by Firebase. As a side effect, it had the benefit of simplifying the code in react-firebase-hooks and maintained type safety.

Thank you for the suggestion, but we won't be switching back to the old approach, so I'll close this PR now