预期 return 箭头函数末尾的值 - immer redux reducer
Expected to return a value at the end of arrow function - immer redux reducer
我将 Immer 与 redux reducer 一起使用,我收到了这个警告
Expected to return a value at the end of the arrow function
我该如何解决?
我的减速器看起来像:
export const optionReducer = (
state = initialState,
action: optionActionTypes
) =>
produce(state, draft => {
switch (action.type) {
case OPTION_GETALL_SUCCESS: {
draft.data = action.payload;
break;
}
default:
return draft;
}
});
在 switch
个分支之一中执行 break
,而在另一个分支中执行 return
。您应该在两者中都使用 return,或者在函数
的末尾同时使用 return 和 break
export const optionReducer = (
state = initialState,
action: optionActionTypes
) =>
produce(state, draft => {
switch (action.type) {
case OPTION_GETALL_SUCCESS: {
draft.data = action.payload;
return draft;
}
default:
return draft;
}
});
我将 Immer 与 redux reducer 一起使用,我收到了这个警告
Expected to return a value at the end of the arrow function
我该如何解决?
我的减速器看起来像:
export const optionReducer = (
state = initialState,
action: optionActionTypes
) =>
produce(state, draft => {
switch (action.type) {
case OPTION_GETALL_SUCCESS: {
draft.data = action.payload;
break;
}
default:
return draft;
}
});
在 switch
个分支之一中执行 break
,而在另一个分支中执行 return
。您应该在两者中都使用 return,或者在函数
export const optionReducer = (
state = initialState,
action: optionActionTypes
) =>
produce(state, draft => {
switch (action.type) {
case OPTION_GETALL_SUCCESS: {
draft.data = action.payload;
return draft;
}
default:
return draft;
}
});