Ich habe einen Fehler mit redux: action.type ist undefiniert. Ich habe es zu einem meiner Aktionen eingrenzen:action.type undefined in 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})
}
})
}
oder vielleicht die Reducer ...
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
}
}
}
}
Also, irgendwie ist der Typ nicht ordnungsgemäß zurückgegeben werden. Wie kann ich das beheben?
EDIT: Thunk wird hier verwendet. Ich fügte auch den Reducer-Code hinzu. Das Zurückbringen der Versandfunktion funktioniert auch nicht. Vielleicht hat das etwas damit zu tun?
Aus welchem Grund auch immer der Fehler bestehen bleibt. – Quesofat
Können Sie Ihren Reducer-Code auch einfügen? – Gautam
Ich habe das getan. Vielen Dank. – Quesofat