-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseFirebaseData.js
More file actions
40 lines (35 loc) · 1.14 KB
/
useFirebaseData.js
File metadata and controls
40 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { initializeApp } = require('firebase/app');
const { getDatabase, ref, get, child } = require('firebase/database');
// Your Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyCnSUsruqVw9DvS5ZUkau_vMBPF6_bc4GA",
authDomain: "riohs-7baf9.firebaseapp.com",
databaseURL: "https://riohs-7baf9-default-rtdb.firebaseio.com",
projectId: "riohs-7baf9",
storageBucket: "riohs-7baf9.appspot.com",
messagingSenderId: "119866808766",
appId: "1:119866808766:web:94a875e3e1def95ba9c1ef"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
const fetchData = async (path) => {
try {
const dbRef = ref(database);
const snapshot = await get(child(dbRef, path));
if (snapshot.exists()) {
console.log('Data received from Firebase:', snapshot.val());
return snapshot.val();
} else {
console.error('No data available at the provided path');
return null;
}
} catch (err) {
console.error('Error fetching data from Firebase:', err);
return null;
}
};
const path = 'CourseData/';
fetchData(path).then(data => {
console.log('Data:', data);
});