Morton
Morton

Reputation: 5760

How to save data on Firebase?

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 });

};

Upvotes: 1

Views: 717

Answers (1)

Parth Ghiya
Parth Ghiya

Reputation: 6949

You are using it wrong.

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

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

Upvotes: 1

Related Questions