How is this meant to be updated for Firebase 9.x? The Firebase 9 docs don't seem to offer any example.
CodePudding user response:
firebaser here
The once('value'
method has been replace by a get()
function, so:
const snapshot = await get(ref);
Also see the Firebase documentation on reading data once.
To unsubscribe from a realtime listener (so not get()
) you now can use the return value from the function you called to subscribe.
So if you subscribe with:
const unsubscribe = onValue(ref, (snapshot) => { ... });
You can then later unsubscribe with:
unsubscribe();
This is what the Firestore SDKs already did, and feedback indicated that devs preferred that over off
.