为什么我的异径管叫两次?请首先找到源代码,并在开发人员工具的屏幕截图下方。
代码:
import { createStore } from 'redux';
const initState = {
title: "-",
todos: []
}
function rootReducer(state = initState, action) {
console.log("rootReducer, state=", state, "rootReducer, action=", action);
if (action.type === "ADD_TODO") {
return {
...state,
todos: [...state.todos, action.todo],
}
}
return state;
}
const store = createStore(rootReducer);
store.subscribe(() => {
console.log("State updated!", store.getState());
});
store.dispatch({ type: 'ADD_TODO', todo: 'Learn Babel' });
谢谢
答案 0 :(得分:1)
第一个调用来自createStore(rootReducer),试图测试您的reducer的不良模式。