Home > Net >  When using onValue to listen to a Firebase realtime database for updates, is it possible to retrieve
When using onValue to listen to a Firebase realtime database for updates, is it possible to retrieve

Time:11-19

I am using the following to query a Firebase realtime database for updates in a React application:

onValue(query(ref(db, 'users')), (snapshot) => {

  if(snapshot.exists()) {
   // do stuff with snapshot.val()
  }

}, (cancelCallback) => {
  console.log(cancelCallback);
});

As expected, this returns all the data that exists under the users node when instantiated and will execute again every time data at this node is changed, added or removed.

Is it possible to retrieve the event type of child_added, child_changed or child_removed from the snapshot?

I have checked the documentation at Firebase and could not find a solution.

CodePudding user response:

Is it possible to retrieve the event type of child_added, child_changed or child_removed from the snapshot?

It's not possible with onValue() but you can use onChildAdded(), onChildChanged() and onChildRemoved() respectively.

  • Related