【问题标题】:How to save data on Firebase?如何在 Firebase 上保存数据?
【发布时间】:2017-04-27 08:06:32
【问题描述】:

我学习了一个使用 React Native 在 Firebase 上保存日期的教程。

当我编译它时显示错误是_firebase2.default.database.ref is not a function

但是官方教程的问题也是.refhttps://firebase.google.com/docs/database/web/read-and-write

任何人都可以教我如何解决这个问题,在此先感谢。

我在 Firebase 上的规则设置:

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
          ".write": "$uid === auth.uid"
      }
    }
  }
}

在 React Native 中保存数据代码:

export const employeeCreate = ({ name, phone, shift }) => {

    const { currentUser } = firebase.auth();

    firebase.database.ref(`/users/${currentUser.uid}/employees`)
    .push({ name, phone, shift });

};

【问题讨论】:

  • 不应该是firebase().database().ref('---whatever---')
  • @ParthGhiya,感谢您回答 firebase.database().ref('---whatever---') 正在工作,非常感谢。
  • 我会把它作为答案发布,你可以接受&UpVote

标签: javascript firebase react-native firebase-realtime-database


【解决方案1】:

你用错了。

当你直接引用firebase时,你应该这样使用它

firebase().database().ref('---whatever---') 

【讨论】:

    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 2018-02-20
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    • 2020-12-18
    相关资源
    最近更新 更多