Javascript 为什么redux状态没有更新?

Javascript 为什么redux状态没有更新?,javascript,reactjs,firebase,redux,google-cloud-firestore,Javascript,Reactjs,Firebase,Redux,Google Cloud Firestore,我有一个Redux动作,但我不能让它工作。 我需要找到嵌套在firebase集合数组中的对象的索引。 从数据库获取数据后,我计算索引,但无法将其发送到redux。 这可能是一个超级noobjavascript错误,我不知道为什么,但我无法更新发送给redux(reDatos)的对象 export const calcularIdsAModificar=(MOid)=>{ 让reDatos={ 莫伊德:莫伊德, MOidindex:null, }; 返回(dispatch,getState,{ge

我有一个Redux动作,但我不能让它工作。 我需要找到嵌套在firebase集合数组中的对象的索引。 从数据库获取数据后,我计算索引,但无法将其发送到redux。 这可能是一个超级noobjavascript错误,我不知道为什么,但我无法更新发送给redux(reDatos)的对象

export const calcularIdsAModificar=(MOid)=>{
让reDatos={
莫伊德:莫伊德,
MOidindex:null,
};
返回(dispatch,getState,{getFirebase,getFirestore})=>{
const Firestore=getFirestore();
const authorId=getState().firebase.auth.uid;
让我们体验一下sarray=‘sin datos’;
Firestore.collection('用户')
.doc(authorId)
.get()
。然后((resp)=>{
experienceAsarray=响应数据().experiencea;
让newindex=experienceAsarray.findIndex((expe)=>expe.id==MOid);
reDatos['MOidindex']=新索引;
})
.then(dispatch({type:'ONCLICK_EDITAR_experienceia',reDatos:reDatos}));
};
};

问题在于:当函数被声明时,第二个
会立即被调用。要使其工作,您需要将处理程序(箭头函数或函数声明)传递给
,然后传递给

这里需要注意的另一件事是,实际上不需要第二个
然后
。由于第一个
之后的
中的代码是同步的,因此可以在其中调用调度

 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.  

    }

你也能分享你的减速机吗?试试switch case希望它能工作:函数Auth(state=initialState,action){switch(action.type){case SIGN\u CALL:state={……state,isLoading:true,};break;default:break;}返回状态;}减速机似乎工作正常,因为它正确地更新了MOid的状态。问题是我不知道如何更新对象(reDatos.MOidindex),然后将其发送到redux reducer。