【问题标题】:How do I send data from my database (Firebase Firestore) to my React Native app?如何将数据从我的数据库 (Firebase Firestore) 发送到我的 React Native 应用程序?
【发布时间】:2021-11-27 23:43:40
【问题描述】:

我在这里遇到了一个小问题。

问题:我正在尝试将数据从连接到 Firestore 的 Firebase Cloud Function(使用 Node.js)发送到我的 react 本机应用程序。我有一个trigger,它在将文档添加到 Firestore 时激活,我想在触发器激活时将数据添加到 redux(在我的应用程序中)。

我知道我必须在如下所示的触发函数中发送信息,但我不确定如何将数据直接发送到 expo 应用程序。

// Example trigger function
exports.createUser = functions.firestore
  .document('users/{userId}')
  .onCreate((snap, context) => {
    // Send information to React Native App
  });

我知道将信息发送到数据库,您只需进行 fetch 或 axios 发布,但是从数据库发送信息让我大吃一惊。

我们将不胜感激任何帮助或指出正确的方向。

【问题讨论】:

    标签: node.js react-native google-cloud-firestore google-cloud-functions expo


    【解决方案1】:

    如果应用程序已经在设备上处于活动状态,常见的方法是将该应用程序的通知写入不同的集合并让应用程序listen on that collection

    如果该应用可能未在设备上使用,常见的方法是send a notification through FCM to the device

    【讨论】:

      猜你喜欢
      • 2017-08-06
      • 2018-04-01
      • 1970-01-01
      • 2021-02-27
      • 2022-01-15
      • 2017-10-22
      • 1970-01-01
      • 2019-08-06
      • 2019-03-30
      相关资源
      最近更新 更多