我正在将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;
}
});
答案 0 :(得分:1)
在switch
的一个分支中,您执行break
,而在另一个分支中,进行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;
}
});