我的reducer文件如下。
import { AppConstants } from '../constants';
const initialState = {
state: [],
menu_items: [],
addon_items: [],
save_items: [],
un_mapped_menu_items: false,
error: ''
};
export default (state = initialState, action) => {
switch (action.type) {
case AppConstants.getMenuItems:
return {
...state,
}
case AppConstants.getMenuItemsSuccess:
return {
...state,
menu_items: action.menu_items
}
case AppConstants.getAddonsItems:
return {
...state,
}
case AppConstants.getAddonsItemsSuccess:
return {
...state,
addon_items: action.addon_items
}
case AppConstants.getMenuItemsEdit:
return {
...state,
}
case AppConstants.getMenuItemsSave:
return {
...state,
save_items: action.save_items
}
case AppConstants.getUnmappedMenuItems:
return {
...state,
error: action.error,
un_mapped_menu_items: true
}
case AppConstants.getMenuItemsError:
return {
...state,
error: action.error
}
default:
return state
}
};
当我调试我的reducer文件时,action.type显示'@@ redux / INIT'。我不明白 。为什么会这样呢?我的操作文件在调试时提供了正确的数据。如何删除此错误?
答案 0 :(得分:6)
创建商店后,@@redux/INIT
createStore
操作
来自守则:
export var ActionTypes = {
INIT: '@@redux/INIT'
}
// When a store is created, an "INIT" action is dispatched so that every
// reducer returns their initial state. This effectively populates
// the initial state tree.
dispatch({ type: ActionTypes.INIT })
请参阅此处的代码: https://github.com/reactjs/redux/blob/v3.0.6/src/createStore.js