由于这很难解释,因此可以在Codesandbox上找到整个源代码:https://codesandbox.io/s/5z9m4lj1ln
问题::action
已正确分发,但reducer
对此没有反应。我还附加了另一个action
,它运行正常。奇怪的是,if
条件并非仅对某些actions
起作用,而其他action
在正常运行。我什至仔细检查了type
的{{1}}的拼写错误,但这似乎不是一个错字。似乎在某些情况下,action
的比较失败了,我也不知道为什么。
是简化代码。如果您无法发现问题,我还在上面的代码和框中用action.type
注释标记了该点。
减速器
// ***this is not reachable!
动作创建者
// reducer
reducerA(state, action) => {
console.log('reducer is working'); // somehow this console message works!
console.log(action) // and I've checked the action from here;
// it appears to be an object with proper type, payload
console.log('DELETED, action.type) // it seems to be the exactly same stuff!
if (action.type === 'DELETED') {
console.log('deleted'); // ***this is not reachable!
return { ...someState };
}
return defaultValue;
}
export default combineReducers({
reducerA,
reducerB // some other reducer
})
有问题的实际组件
export const deleteOp = title => {
return {
type: "DELETED",
payload: title
};
};
你能指出我是否想念什么?