3

I'm new to React Native and doing a project following some online tutorials. In given step, I have created a Firebase database (also added some dummy data and set a standard rule). In my React Native project, to fetch data after user being authenticated from Firebase, I'm doing following action :

import firebase from 'firebase';
export const loadInitialContacts = () =>
{
    const {currentUser} = firebase.auth();

    return (dispatch) => {
        firebase.database.ref(`/users/${currentUser.uid}/people`)
            .on('value', snapshot => {
                dispatch({type: 'INITIAL_FETCH', payload: snapshot.val()});
            });
    };
};

I'm calling the above method from my list view Component :

componentWillMount()
{
    this.props.loadInitialContacts();
}

Authentication to Firebase pass successfully, at the time of fetching data from Firebase it throws exception :

Error: TypeError: TypeError: _firebase2.default.database.ref is not a function

What I'm doing wrong?

Looking into the package.json, I'm on this following version :

"dependencies": {
    "firebase": "^5.0.2",
    "lodash": "^4.17.10",
    "react": "16.3.1",
    "react-native": "^0.55.4",
    ...
  },
5
  • 4
    try firebase.database().ref Commented Jun 14, 2018 at 6:40
  • 1
    instead of firebase.database.ref Commented Jun 14, 2018 at 6:41
  • Thank you! That clears the given error! Commented Jun 14, 2018 at 6:51
  • Unfortunately, the above call anyway returns me null even when I have some dummy record added to the database. Commented Jun 14, 2018 at 6:59
  • It looks like .on('value', snapshot => { never pass successfully. Commented Jun 14, 2018 at 7:08

1 Answer 1

2

I faced a similar error. My original code was:

    const rootRef = firebase.database.ref().child('react');

However, I changed it to

    const rootRef = firebase.database().ref().child('react');

and it worked.

Change firebase.database().ref from firebase.database.ref

Sign up to request clarification or add additional context in comments.

1 Comment

Do you happen to know where we can find modern day documentation on how you got your answer to work for you in your environment?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.