我试图通过在我的 redux saga 中调用 put 方法来触发 redux reducer,但它没有被触发,即使我返回应该在我的 reducer 中捕获的相同操作类型。这是我的传奇:export function* registrationSaga(action) { try { const response = yield call(registerUser, action.payload); console.log(response) yield put({ type: REGISTER_USER_SUCCESS, response }) } catch(error) { yield put({ type: REGISTER_USER_ERROR, error }); }}这是我的减速器:export const registrationReducer = (state = {}, action) => {let response = action.response;switch(action.type) { case REGISTER_USER_SUCCESS: { console.log("successful registration") return { ...state, registration_success: response.success, registration_message: response.message }; } case REGISTER_USER_ERROR: return { ...state, registration_success: response.success, registration_message: response.message }; default: return state;}}我希望在我的控制台中看到“成功注册”并在我的组件中将该响应作为道具获得,但这并没有发生。什么应该导致这个问题?这是我的 rootReducer 和商店:const rootReducer = () => combineReducers({ registrationReducer, todoReducer})export default rootReducer;并存储:const sagaMiddleware = createSagaMiddleware()export const store = createStore( rootReducer, applyMiddleware(sagaMiddleware));sagaMiddleware.run(rootSaga)
1 回答
SMILET
TA贡献1796条经验 获得超4个赞
rootReducer不应该是调用的函数combineReducers,而应该是以下的返回值combineReducers:
const rootReducer = combineReducers({
registrationReducer,
todoReducer,
});
export default rootReducer;
添加回答
举报
0/150
提交
取消