FirebaseExtended / reactfire

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

Question! Are multiple subscriptions opened in this case? #603

Closed seanaguinaga closed 6 months ago

seanaguinaga commented 6 months ago

In two different components, the same document is subscribed to

export function DisplayName() {
  const db = useFirestore();
  const ref = useRef<HTMLButtonElement | null>(null);
  const [status, setStatus] = useState<'loading' | 'sucess' | 'error' | 'idle'>('idle');
  const { user, profile, updateProfile } = useUser();

  const { data } = useFirestoreDocData(doc(db, `profiles/${user.uid}`), {
    idField: 'id',
  });
export function Username() {
  const db = useFirestore();
  const ref = useRef<HTMLButtonElement | null>(null);
  const [status, setStatus] = useState<'loading' | 'sucess' | 'error' | 'idle'>('idle');

  const { user, profile, updateProfile } = useUser();

  const { data } = useFirestoreDocData(doc(db, `profiles/${user.uid}`), {
    idField: 'id',
  });

Will this open two subscriptions or just open one and share the data via the observable cache?

seanaguinaga commented 6 months ago

I am asking because useFirestoreDocDataOnce does not seem to share local updates between components