use next.js
update and set work without problems, but when I want to read using on, an error occurs, in the settings firebase checked for me read and write = true
import { getDatabase,ref,set,once,on,update,onChildAdded} from 'firebase/database';
const reference = ref(db, 'room/' 'new');
// get support data from firebase
reference.on('value',function (snapshot) {
console.log("In Value");
console.log(snapshot.val());
}, function(error) {
console.error(error);
});
I get an error
reference.on is not a function at startSubmit
my firebase
CodePudding user response:
There is a onValue()
function in the new Modular SDK to listen for updates at the database reference. Try refactoring the code like this:
import { getDatabase, ref, onValue} from "firebase/database";
const reference = ref(db, 'room/' 'new');
onValue(reference, (snapshot) => {
const data = snapshot.val();
console.log(data)
});
Checkout the documentation for more information.