reactfire icon indicating copy to clipboard operation
reactfire copied to clipboard

Support withConverter

Open louis030195 opened this issue 2 years ago • 1 comments

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>>
}

louis030195 avatar Sep 06 '21 11:09 louis030195

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 avatar Sep 08 '21 15:09 jhuleatt

This is fixed now that ReactFire uses RxFire 6.0.3.

jhuleatt avatar Aug 17 '22 18:08 jhuleatt