Redux Saga 不拦截动作

时间:2021-03-11 12:39:57

标签: redux react-redux redux-saga

我的 redux saga 中间件有问题,它对我的​​操作不起作用。操作本身正在运行并被执行。我所有的saga都收集在index-saga中,然后按照我的store配置运行

期望: 我希望 authSaga 在运行我的 signUp 操作后打印 console.log 语句:console.log('signUpintercept')

现实: 什么都没发生

index js
import 'react-native-gesture-handler';
import React from 'react';
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import {Provider} from 'react-redux';
import {createStore, combineReducers, applyMiddleware} from 'redux';
import createSagaMiddleware from 'redux-saga';
import IndexSagas from './src/redux/sagas/index-sagas';
const rootReducer = combineReducers({auth: authReducer});
const sagaMiddleware = createSagaMiddleware();

//eslint-disable-next-line no-underscore-dangle
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const store = createStore(
  rootReducer,
  composeEnhancers(applyMiddleware(sagaMiddleware)),
);
sagaMiddleware.run(IndexSagas);

    const RNRedux = () => {
      return (
        <Provider store={store}>
          <App />
        </Provider>
      );
    };
    AppRegistry.registerComponent(appName, () => RNRedux);

我的索引传奇

import authWatcher from './authSaga';

export default function* IndexSagas() {
  yield [authWatcher()];
}

我的身份验证传奇

import {put, takeLatest, all} from 'redux-saga/effects';
import {SIGN_UP} from '../constants/index';

function* signUpFlow() {
  console.log('signUp intercept');
  
}

export default function* authWatcher() {
  yield [takeLatest(SIGN_UP, signUpFlow)];
}

我的行动:

import {SIGN_UP} from '../constants/index';
export const signUp = (nickname: string, email: string, password: string) => {
  return {
    type: SIGN_UP,
    nickname,
    email,
    password,
  };
};

非常感谢您的帮助。谢谢!

0 个答案:

没有答案