Answer the question
In order to leave comments, you need to log in
Why is firebase data re-rendered in console?
Hello. I am making a react native app and using firebase database.
Problem: I first call the get_data_DB function several times (for example 5 times) and it works fine, I get what I want. But after that I call the updateDB function (to set a new value to the firebase database), but it works strangely - it prints the value from the database to the console several times in a row (as many times as I called the get_dataDB function). But the fact is that in the updateDB function I do not call console.log () at all, especially several times.
// получение данных из firebase база данных в реальном времени
const get_data_DB = () => {
const database = firebase.database().ref('1').on('value', (snapshot) => {
const highscore = snapshot.val().field1;
console.log(highscore);
})
}
// установить новые данные в firebase база данных в реальном времени
function updateDB(userID, fieldValue1, fieldValue2) {
firebase.database().ref(userID).set({
field1: fieldValue1,
field2: fieldValue2,
});
}
Answer the question
In order to leave comments, you need to log in
I do not understand these firebases, and I can only assume:
1. you create event listeners with your get_data_DB calls (5 times). each run is a unique listener.
2. updateDB call inserts data and generates an update event (for which you already have 5 listeners). and they all show in the console, because you yourself wrote it in the listener.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question