How to save data on Firebase?

◇◆丶佛笑我妖孽 提交于 2020-01-05 07:53:47

问题


I take a tutorial to save date on Firebase in React Native.

When i compile it that show the error is _firebase2.default.database.ref is not a function

But the question that offcial tutorial is .ref too. https://firebase.google.com/docs/database/web/read-and-write

Any one can teach me how to solve the issue , thanks in advance.

My rules setting on Firebase:

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

Save data code in React Native:

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

    const { currentUser } = firebase.auth();

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

};

回答1:


You are using it wrong.

When u directly reference firebase, you should use it like this

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


来源:https://stackoverflow.com/questions/43652067/how-to-save-data-on-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!