Home Ask Login Register

Developers Planet

Your answer is one click away!

nicholas February 2016

Firebase 'value' events aren't firing in React Native

I have a function that is mean to subscribe to value events on a firebase child url. It looks like

function getMessages(chat) {
  var ref = new Firebase(".../"+chat+"/messages");
  ref.limitToLast(10).on('value', function(snapshot) {
    ...
  });
}

This is called from a React component's componentWillMount method like so:

componentWillMount() {
    getMessages(this.props.chat);
}

The first time I call this function, everything works and it's blazing fast. But if I call it with a different chat parameter the callback never fires. Not even once for the first load.

As far as I can tell, by putting console.log's on every other line, componentWillMount is firing and getMessages is being called.

What gives? Any ideas?

Thanks.

Edit: Note I'm trying to implement this in React Native. I've simplified even further, and have my React component connecting to firebase directly. Check out this fiddle. This is working perfectly in the fiddle, but in React Native while it connects the first time, if you click back and go into another chat, it will never fire the value event.

Answers


nicholas February 2016

In an entirely new project, it seems to work, so the problem must be somewhere else. Here's a gist.

Post Status

Asked in February 2016
Viewed 1,615 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life