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.