我尝试了什么
case 'FETCH_APPOINTMENT':
return { ...state, appointment: action.payload.data };
case 'SOME_CASE':
return {
[state && state.appointment]: state && state.appointment,
..._.mapKeys(action.payload.data, 'id'),
};
result
{undefined: undefined}
结果是他们无法定义状态。约会
答案 0 :(得分:1)
这应该有效。您可以通过在化简器state && state.appointment
中为appointment
添加默认值来删除initialState
真实性检查:
const initialState = {
appointment: 'A'
};
const reducers = (state = initialState, action) => {
switch(action) {
case "SOME_CASE": {
return {
[state.appointment]: {
...[state.appointment],
_.mapKeys(action.payload.data, 'id')
}
}
}
}
}