React Reducer无法识别action.type比较

时间:2019-03-11 17:20:36

标签: javascript reactjs redux react-redux reducers

由于这很难解释,因此可以在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
  };
};

你能指出我是否想念什么?

0 个答案:

没有答案