Here is the problem: the second then
gets called imediatelly when the function is declared. For it to work, you need to pass handler (arrow function or funciton declaration) to the then
.
Another thing to note here is that you don't actually need the second then
. Since the code inside the first then
is synchronous, you could call the dispatch inside it.
return (dispatch, getState, {getFirebase, getFirestore}) => {
const Firestore = getFirestore();
const authorId = getState().firebase.auth.uid;
let experienciasArray = 'sin datos'
Firestore.collection('users').doc(authorId).get().then(resp => {
experienciasArray = resp.data().experiencia
let newindex = experienciasArray.findIndex(expe => expe.id === MOid)
reDatos['MOidindex'] = newindex
dispatch({ type:'ONCLICK_EDITAR_EXPERIENCIA', reDatos: reDatos })
});
//.then(() => ?{dispatch...}); //Or call a dispatch inside an arrow function here.
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…