0
0
Firebasecloud~5 mins

Real-time listeners (onSnapshot) in Firebase - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of onSnapshot in Firebase?

onSnapshot listens to changes in real-time on a Firestore document or collection. It updates your app immediately when data changes.

Click to reveal answer
beginner
How does onSnapshot differ from a one-time data fetch?

onSnapshot keeps listening for updates continuously, while a one-time fetch gets data only once and stops.

Click to reveal answer
intermediate
What is the role of the unsubscribe function returned by onSnapshot?

The unsubscribe function stops the real-time listener to save resources when you no longer need updates.

Click to reveal answer
beginner
Can onSnapshot listen to both documents and collections?

Yes, onSnapshot can listen to a single document or an entire collection to track changes in real-time.

Click to reveal answer
intermediate
Why is it important to handle errors in onSnapshot listeners?

Handling errors ensures your app can respond to permission issues or network problems gracefully without crashing.

Click to reveal answer
What does onSnapshot do in Firebase Firestore?
AListens for real-time updates to data
BFetches data only once
CDeletes data from Firestore
DCreates a new document
What should you do when you no longer need updates from onSnapshot?
ACall <code>onSnapshot</code> again
BCall the unsubscribe function returned by <code>onSnapshot</code>
CReload the page
DNothing, it stops automatically
Which of these can onSnapshot listen to?
ABoth documents and collections
BOnly documents
COnly collections
DNeither documents nor collections
Why is error handling important in onSnapshot listeners?
AError handling is not needed
BTo speed up data fetching
CTo automatically fix data errors
DTo prevent app crashes and handle permission or network issues
What happens if you do not unsubscribe from an onSnapshot listener?
AThe app crashes immediately
BThe listener stops automatically after 5 minutes
CThe listener keeps running and may waste resources
DThe data stops updating
Explain how onSnapshot helps keep your app data up to date in real-time.
Think about how your app can show new data without refreshing.
You got /4 concepts.
    Describe best practices when using onSnapshot listeners in a Firebase app.
    Consider resource use and app stability.
    You got /4 concepts.