FirebaseExtended / reactfire

Hooks, Context Providers, and Components that make it easy to interact with Firebase.
https://firebaseopensource.com/projects/firebaseextended/reactfire/
MIT License
3.52k stars 401 forks source link

Support withConverter #445

Closed louis030195 closed 2 years ago

louis030195 commented 3 years ago

Version info

React: 17.0.2

Firebase: 8.3.1

ReactFire: 3.0.0

Expected behavior

export const converter = <T>():
    firebase.firestore.FirestoreDataConverter<T> => ({
    toFirestore: (data: Partial<T>) => data,
    fromFirestore: (snap: firebase.firestore.QueryDocumentSnapshot) =>
        snap.data() as T,
  });

interface Foo {}
const FooComponent = (props: any) => {
  const fs = useFirestore();
  const foos = useFirestoreCollection(
      fs.collection("foos")
          .withConverter(converter<Foo>())
  );
 // foos type ObservableStatus<firebase.firestore.QuerySnapshot<Foo>>
}

Actual behavior

export const converter = <T>():
    firebase.firestore.FirestoreDataConverter<T> => ({
    toFirestore: (data: Partial<T>) => data,
    fromFirestore: (snap: firebase.firestore.QueryDocumentSnapshot) =>
        snap.data() as T,
  });

interface Foo {}
const FooComponent = (props: any) => {
  const fs = useFirestore();
  const foos = useFirestoreCollection(
      fs.collection("foos")
          .withConverter(converter<Foo>())
  );
  // foos type ObservableStatus<firebase.firestore.QuerySnapshot<firebase.firestore.DocumentData>>
}
jhuleatt commented 3 years ago

Thanks for reporting this, @louis030195. I think this will be an easy fix in ReactFire once https://github.com/FirebaseExtended/rxfire/pull/33 is released

jhuleatt commented 2 years ago

This is fixed now that ReactFire uses RxFire 6.0.3.