scrimba
Frontend Career Path
Making websites interactive
Build a Mobile App
Aside: Fetching database items in realtime using onValue
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Aside: Fetching database items in realtime using onValue
AboutCommentsNotes
Aside: Fetching database items in realtime using onValue
Expand for more info
index.js
run
preview
console
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js"
import { getDatabase, ref } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-database.js"

const appSettings = {
databaseURL: "https://playground-c5b18-default-rtdb.europe-west1.firebasedatabase.app/"
}

const app = initializeApp(appSettings)
const database = getDatabase(app)
const booksInDB = ref(database, "books")

const booksEl = document.getElementById("books")

function clearBooksListEl() {
booksEl.innerHTML = ""
}

function appendBookToBooksListEl(bookValue) {
booksEl.innerHTML += `<li>${bookValue}</li>`
}
Console
/index.html
-10:22