0

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.

Kartiikeya
  • 2,358
  • 7
  • 33
  • 68
  • Have you validated in the devtools/action logger that the action is not being dispatched twice? – phry Jun 28 '22 at 09:59
  • If you're dispatching the action in a useEffect and you're running in strict mode it might be dispatching the action twice. – Chad S. Jun 29 '22 at 17:10

0 Answers0