Dmitri Borohhov
Dmitri Borohhov

Reputation: 1603

SyntaxError exception in React Native Firebase Database

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

Upvotes: 0

Views: 232

Answers (2)

Dmitri Borohhov
Dmitri Borohhov

Reputation: 1603

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.

Upvotes: 1

Yash
Yash

Reputation: 3576

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

Upvotes: 0

Related Questions