Redux Saga方法被称为两次(React Native)

发布于 2025-02-11 06:50:58 字数 1375 浏览 2 评论 0原文

在React Native应用中,Redux Saga方法被称为两次。

请找到

SAGA.TS,

export function* fetchValueLable(action: IFluxStandardAction<ILables>) {
  try {
    if (!action.payload) {
      return;
    }
    
    const response = yield call(serviceClass.getLables, payload);
    if (response.success && response.lines != null) {
      yield put(Actions.fetchLableSuccess(AvailableLables));
    } else {
    }
  } catch (e) {
    yield put(Actions.fetchLableFailure(e.message));
  }
}

function* watchLable() {
  yield takeLatest(FfsActionTypes.FETCH_LABEL, fetchValueLable);
}

export const LableSaga = {
    watchLable,
};

请从组件级别找到Redux配置

const configureStore = (): Store<IState> => {
  // Redux configurations
  const middleware = [];
  const enhancers = [];
  const sagaMiddleware = createSagaMiddleware();
  middleware.push(sagaMiddleware);

  const storeConfig: Store<IState> = createStore(rootReducer, compose(...enhancers));

  sagaMiddleware.run(rootSaga);

  return storeConfig;
};
StoreProviderService.init(configureStore);
const store = StoreProviderService.getStore();

,调度操作部分

return bindActionCreators({
      fetchLableValue,
    },
    dispatch);
};

export default connect(mapStateToProps, mapDispatchToProps)(component);

请让我知道如何修复此重复的传奇调用。

Redux saga method is being called twice in React native application.

Please find

saga.ts

export function* fetchValueLable(action: IFluxStandardAction<ILables>) {
  try {
    if (!action.payload) {
      return;
    }
    
    const response = yield call(serviceClass.getLables, payload);
    if (response.success && response.lines != null) {
      yield put(Actions.fetchLableSuccess(AvailableLables));
    } else {
    }
  } catch (e) {
    yield put(Actions.fetchLableFailure(e.message));
  }
}

function* watchLable() {
  yield takeLatest(FfsActionTypes.FETCH_LABEL, fetchValueLable);
}

export const LableSaga = {
    watchLable,
};

Please find redux configurations

const configureStore = (): Store<IState> => {
  // Redux configurations
  const middleware = [];
  const enhancers = [];
  const sagaMiddleware = createSagaMiddleware();
  middleware.push(sagaMiddleware);

  const storeConfig: Store<IState> = createStore(rootReducer, compose(...enhancers));

  sagaMiddleware.run(rootSaga);

  return storeConfig;
};
StoreProviderService.init(configureStore);
const store = StoreProviderService.getStore();

from Component level , dispatch action part

return bindActionCreators({
      fetchLableValue,
    },
    dispatch);
};

export default connect(mapStateToProps, mapDispatchToProps)(component);

Please let me know how i can fix this duplicate saga calls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文