这些是我目前的动作创作者,他们运行良好&像往常一样返回行动。我已经测试了一些日志,它在这里工作:
export function stateToEntry() {
return { type: types.STATE_TO_ENTRY, formState: 'entry-mode'};
}
export function stateToEdit() {
return { type: types.STATE_TO_EDIT, formState: 'edit-mode'};
}
export function stateToDelete() {
return { type: types.STATE_TO_DELETE, formState: 'delete-mode'};
}
这是我现在的减速机,它没有接受我的动作。我在这里测试过,似乎我甚至无法登录控制台:
import * as types from '../actions/actionTypes';
export default function formStateReducer(state = [], action) {
switch(action.type) {
case types.STATE_TO_ENTRY:
console.log('entry-mode');
return {formState: action.formState};
case types.STATE_TO_EDIT:
//console.log('edit-mode');
return {formState: action.formState};
case types.STATE_TO_DELETE:
//console.log('delete-mode');
return {formState: action.formState};
default:
return state;
}
}
这是我的组合减速机。位置reducer工作正常,但我在formState上得到一个null,因此它在商店内正确链接。 :
const rootReducer = combineReducers({
locations,
formStates
});
export default rootReducer;
我可能错过了什么?
答案 0 :(得分:1)
从文档:bindActionCreators
...将一个值为动作创建者的对象转换为具有相同键的对象,但将每个动作创建者包装到一个调度调用中,以便可以直接调用它们。 / p>
所以,你错误地使用它,试试这个:
let foo = {
location: bindActionCreators(locationActions, dispatch),
form: bindActionCreators(formActions, dispatch)
}
// later in your code -- will dispatch that action automatically
foo.location.someActionFromLocationActionsObject()