【问题标题】:react native redux saga does not runreact native redux saga 不运行
【发布时间】:2021-06-17 22:49:08
【问题描述】:

为什么我的传奇没有运行?我没有收到消息“console.log('hi')”。

sagaAuth.js

import { all, call, put } from 'redux-saga/effects';

function* hello() {
  while(true) {
    console.log('hi')
  }
};

export default function*() {
  yield all([hello])
};

rootSaga.js

import { all } from 'redux-saga/effects';
import authSaga from './saga/auth';

export default function* () {
  yield all([authSaga]);
}

商店

import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit';
import reducers from './reducers';
import createSagaMiddleware from 'redux-saga';
import saga from './saga';

const sagaMiddleware = createSagaMiddleware();

const store = configureStore({
  reducer: reducers,
  middleware: getDefaultMiddleware => getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware)
});

sagaMiddleware.run(saga);

export default store;

....................... ....................

【问题讨论】:

    标签: react-native redux expo redux-saga


    【解决方案1】:

    尝试将您放入 all 的 saga 包装在 fork 效果中,如下所示:

    import {all, fork} from 'redux-saga/effects';
    
    export default function* () {
      yield all([fork(authSaga)]);
    }
    ...
    export default function*() {
      yield all([fork(hello)]);
    };
    

    还要避免内部没有阻塞效果的无限循环。您现在拥有的 console.log 可能会在您打开开发工具之前冻结您的应用程序。

    【讨论】:

      猜你喜欢
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 2018-05-25
      相关资源
      最近更新 更多