Hello guys and girls :)
I'm starting with Firebase && Redux and I'm having some issues with the callback on
-function of firebase.database().ref()
within the formular
function getAll() {
const uid = JSON.parse(localStorage.getItem('user'))
.uid;
const dbRef = firebase.database()
.ref().child('events');
const userRef = dbRef.child(uid);
let answer = [];
userRef.on('value', snap => {
let rx = snap.val();
for (let item in snap.val()) {
answer.push(rx[ item ]);
}
});
return Promise.resolve({
events: answer
});
}
What was I doing ?
I've created before some actions (triggers) to call this services and this method must fire before the result be saved with reducers in the store
.
This is what is expected. But,...
What is my actual reality ?
- The method fires in time, good new :-) but,
- The
callback
(as it is) fires some seconds after (1
or1.5s
) while theredux
itself, very fast unit, fires and make the react render at the same time. In short, the components are rendered lots before the firebase callback gives back a value.
At the final then I need to render, reload the page, change to another route of the application so that the saved changes can be applied to render.
Since I'm beginning with redux and firebase, I'm not 100%
(but only 70%
) sure of this deductions, but they are the betters I could've found in this situation.
What's then the situation ?
I'm starving for any help now and thank you for any help you could provide me :)