-2
我有一个与redux的错误:action.type是未定义的。我已经收窄,到我的行动之一:action.type在redux中未定义
export function LOAD_PRODUCTS() {
axios.get('http://localhost:3000/api/products')
.then((res) => {
return (dispatch) => {
dispatch({type: 'PRODUCTS_LOADED', payload: res})
}
})
.catch((err) => {
return (dispatch) => {
dispatch({type: "PRODUCTS_ERROR", payload: err})
}
})
}
或可能的减速...
export function reducer(
state = {
fbkey: '',
userSuccess: null,
cart: [],
nav: null,
tab: true,
error: {},
loading: false,
products: []
}, action) {
switch (action.type) {
case "FBTOKEN": {
return {
...state,
fbkey: action.payload
}
}
case "NAV_OPEN" : {
return {
...state,
nav: true
}
}
case "NAV_CLOSE" : {
return {
...state,
nav: false
}
}
case "USER_SUCCESS" : {
return {
...state,
userSuccess: true
}
}
case "USER_ERROR" : {
return {
...state,
userSuccess: false
}
}
case "ADD_TO_CART" : {
return {
...state,
cart: action.payload
}
}
case "TAB_CLOSE": {
return {
...state,
tab: action.payload
}
}
case "TAB_OPEN": {
return {
...state,
tab: action.payload
}
}
case "PRODUCTS_LOADED": {
return {
...state,
products: action.payload
}
}
case "PRODUCTS_ERROR": {
return {
...state,
error: action.payload
}
}
case "IS_LOADING": {
return {
...state,
loading: action.payload
}
}
case "IS_NOT_LOADING": {
return {
...state,
loading: action.payload
}
}
default: {
return {
...state
}
}
}
}
所以,不知何故没有被正确的返回类型。我该如何解决这个问题?
编辑:这里使用的是Thunk。我还添加了reducer代码。返回调度功能也不起作用。也许它与此有关?
调度试无论出于何种原因的错误仍然存在。 – Quesofat
你也可以粘贴你的reducer代码吗? – Gautam
我做到了。谢谢。 – Quesofat