如何解决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时,都会抛出: 输入错误,无法准备null的属性'entrega'
这发生在移动设备和台式机中,我尝试使用!! state.userData吗? state.userData:{},错误仍然存在,但是在另一个组件中,我调用了相同的userData状态(大约5个或更多组件),但是即使我以这种方式解决了所有问题,消息错误也只会回到第一个发生,并且仅在Google Chrome中发生
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。