// This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // // To update the snippets in this file, edit the source and then run // 'npm run snippets'. // [START use_from_cache_modular] import { collection, onSnapshot, where, query } from "firebase/firestore"; const q = query(collection(db, "cities"), where("state", "==", "CA")); onSnapshot(q, { includeMetadataChanges: true }, (snapshot) => { snapshot.docChanges().forEach((change) => { if (change.type === "added") { console.log("New city: ", change.doc.data()); } const source = snapshot.metadata.fromCache ? "local cache" : "server"; console.log("Data came from " + source); }); }); // [END use_from_cache_modular]