0

I can't get Firebase realtime database data, getting exception and can't understand why.

"SyntaxError: Unexpected end of input
at App.componentDidMount (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:1571:45)
at App.proxiedComponentDidMount (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:57980:42)
at commitLifeCycles (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:31136:28)
at commitLayoutEffects (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:33340:13)
at Object.invokeGuardedCallbackImpl (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:20647:16)
at invokeGuardedCallback (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:20743:37)
at commitRootImpl (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:33172:15)
at unstable_runWithPriority (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:55717:18)
at runWithPriority (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:24203:16)
at commitRoot (blob:http://localhost:8081/debac782-dd29-4750-a1b8-dc8e57c59632:33041:9)"

In the App.js constructor I initialize firebase like this (works fine):

if (!firebase.apps.length) {
    firebase.initializeApp(config);
}

And in componentDidMount() I am trying to get the database ref:

    componentDidMount() {            
        firebase.database().ref('listings').once("value", snapshot => {
          //handle snapshot data
        });         
   }
5
  • Did you activate the database from console? Commented Aug 23, 2019 at 17:27
  • No, why? The instruction says nothing about that firebase.googleblog.com/2016/01/… Commented Aug 23, 2019 at 17:31
  • I am sure but i think ref('lintings').once.....i think mistake is once....instend of once ,there should be on Commented Aug 23, 2019 at 17:37
  • .on() is for continuous polling, .once() is for a single read. The error is the same. Commented Aug 23, 2019 at 17:40
  • @DmitriBorohhov I've added my answer. I think you need to make change to reference call. Take care of the syntax. Commented Aug 23, 2019 at 17:41

2 Answers 2

1

It seems like the remote debugger for React Native is causing syntax errors in bundling. Once I disable remote debugging, the issue disappears and I can get the data from Firebase database.

This looks to be the same as described in the Github issue.

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

Comments

0

Take care of the syntax:

firebase.database().ref('listings').once('value').then(function(snapshot) {
  // handle snapshot data
});

.once() returns a Promise<DataSnapshot> hence, you need to handle it with .then()

once

once(eventType: EventType, successCallback?: function, failureCallbackOrContext?: function | Object | null, context?: Object | null): Promise<DataSnapshot>

From https://firebase.google.com/docs/reference/js/firebase.database.Reference.html#once

2 Comments

Tried your suggestion, didn't work. The syntax is just a lambda expression, which worked fine on a React web project, so I wonder why it doesn't work in a clean React Native project. The second argument of the .once() function is a successCallback, which returns a DataSnapshot when ready.
Yes, I did. No change.

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.