0Pricing
Firebase Auth & Realtime Database Apps · Lesson

Listening for Realtime Changes

Make your app truly live by subscribing to Realtime Database events, reacting to value and child changes as they happen, and cleaning up listeners to avoid leaks.

From Fetch to Stream

Reading data once gives you a snapshot. The power of Realtime Database is live updates: your app reacts the instant data changes on the server, with no polling.

This is done by attaching listeners to a location in the database.

The Value Event

The most common listener is value. It fires once immediately with current data, then again every time anything under that location changes.

import { getDatabase, ref, onValue } from 'firebase/database';

const db = getDatabase();
onValue(ref(db, 'scores/global'), (snapshot) => {
  console.log('New value:', snapshot.val());
});

All lessons in this course

  1. Realtime Database Fundamentals
  2. Reading & Writing Data
  3. Structuring Your Data
  4. Listening for Realtime Changes
← Back to Firebase Auth & Realtime Database Apps