Google Chrome中的React Redux引发“ TypeError:无法读取null的属性'entrega'”

问题描述

我正在使用firefox,并且一切正常,但是当我使用chrome测试时,应用程序崩溃了,我听不懂

我正在使用react(v16.13.1)和redux(4.0.5),首先,我需要在许多组件之间共享状态,并且正如我之前所说,在Firefox中工作正常,但是在Firefox中崩溃了chrome,我有三个主要的reducer,companyData,cartIten和userData,两个第一个都很好用,但是每次我尝试通过useSelector(state => state.userData)调用userData时,它在chrome中崩溃,请转到我的代码

// the Schedule.js top,before the

export default ({ entrega }) => {

const { entrega } = useSelector(state => state.companyData.data.payload);

  const entregarDados = useSelector( state => state.userData.entrega ); // here is where the error occurs
  
  return(
    // the component itself
  );

和减速器:

// I hide the mports to show only the important code here

const initialState = {
    nome: "",telefone: "",coupon: null,entrega: {},agendar: {},metodo_pagamento: "",metodo_entrega: "",presente: false
}

export default (state = initialState,action) => {
    switch(action.type) {
        case USER_SET_ALL:
            return action.payload
        case USER_ADDRESS:

            const address = {
                metodo_entrega: state.entrega.metodo_entrega ? state.entrega.metodo_entrega : null,...action.payload
            };

            return {
                ...state,entrega: address
            };
        case DELIVERY_METHOD:

            return {
                ...state,metodo_entrega: action.payload
            }
        default:
        return state;
   }
}

最后是合并的出口:

export default combineReducers({
    companyData,categoryData,cartData,cartIten,removeScroll,userData,});

但是每次我尝试在chrome中调用userData时,都会抛出:

enter image description here

输入错误,无法准备null的属性'entrega'

这发生在移动设备和台式机中,我尝试使用!! state.userData吗? state.userData:{},错误仍然存​​在,但是在另一个组件中,我调用了相同的userData状态(大约5个或更多组件),但是即使我以这种方式解决了所有问题,消息错误也只会回到第一个发生,并且仅在Google Chrome中发生

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)