【问题标题】:I want to auto update the list in the screen with firebase我想用 firebase 自动更新屏幕中的列表
【发布时间】:2021-05-11 11:53:41
【问题描述】:

我的应用使用 Reactjs(redux、hook、context)、Nestjs 和 Firebase。如何创建数据然后自动更新列表?该列表将显示在独立屏幕(其他计算机)中,因此我需要自动更新它。

Nestjs:
main.ts:
const adminConfig: ServiceAccount = {
  "projectId": configService.get<string>('FIREBASE_PROJECT_ID'),
  "privateKey": configService.get<string>('FIREBASE_PRIVATE_KEY')
                        .replace(/\\n/g, '\n'),
  "clientEmail": configService.get<string>('FIREBASE_CLIENT_EMAIL'),
};

admin.initializeApp({
  credential: admin.credential.cert(adminConfig),
});

Reactjs:
firebase.js:
var firebaseConfig = {
  apiKey: "xxxx",
  authDomain: "myhealthqlpkv3.firebaseapp.com",
  projectId: "myhealthqlpkv3",
  storageBucket: "myhealthqlpkv3.appspot.com",
  messagingSenderId: "xxxx",
  appId: "xxxxx",
  measurementId: "xxxx"
};
// Initialize Firebase
const firebaseApp = firebase.default.initializeApp(firebaseConfig);

export default firebaseApp ;

【问题讨论】:

    标签: reactjs nestjs


    【解决方案1】:

    您可以使用 onSnapshot 方法来监听或等待数据库或集合的任何变化,并根据需要响应返回的数据。

    //https://firebase.google.com/docs/firestore/query-data/listen#web-v8_2

    【讨论】:

    • 朋友告诉我这里不需要实时数据库或firestore,因为不需要通知。但正如我所见,onSnapshot 与 Firestore 一起使用?
    • 如果您不使用 Firestore,请改用 on 或 once 函数。文档中的更多信息:firebase.google.com/docs/database/web/….
    • 到底有没有不使用数据库(实时数据库和 Firestore 数据库)?因为我的数据没有保存在这些数据库中,所以保存在单独的服务器中。
    • 什么意思?根据上面的配置,你的数据库在firebase中。您的数据在哪里,或者您实际使用的是哪个数据库?
    • 对不起,我已经重新更新了,在这种情况下,我不使用实时数据库或 Firestore 数据库。我的主数据库位于单独的服务器中。这里的主数据库不是火力基地。如果我想从中获取数据,我必须使用 api。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 2017-11-28
    • 2021-05-27
    • 2020-03-04
    • 2022-01-23
    相关资源
    最近更新 更多