为了账号安全,请及时绑定邮箱和手机立即绑定

Redux-saga put 方法不会触发减速器

Redux-saga put 方法不会触发减速器

慕森王 2021-11-18 16:14:16
我试图通过在我的 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;


查看完整回答
反对 回复 2021-11-18
  • 1 回答
  • 0 关注
  • 183 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信