首页 > 解决方案 > 我们如何从 SAGA 中的生成器函数中导出变量?

问题描述

export function* getContacts(action: PayloadAction<SearchQuery>) {
  const stationCode = action.payload.stationCode;
  console.log(stationCode);////// Want stationCode from here to outside 
  const requestURL = `${API_PATH}contacts/departments/${stationCode}`;
  const requestOptions = {
    credentials: 'same-origin',
    method: 'GET',
  };
  try {
    yield put(actions.setIsLoading(true));
    let contactList = yield call(request, requestURL, requestOptions);
    transformContacts(contactList);
    yield put(actions.setContactRecords(contactList));
    yield put(actions.setIsLoading(false));
  } catch (err: any) {
    let errorObject: ErrorObject = { status: err.status, message: '' };
    if (err.status === 400) {
      errorObject.message = 'Invalid Station Code';
    } else {
      errorObject.message =
        'We are observing a technical issue...Please try again later';
    }
    yield put(actions.loadStationsError(errorObject));
    yield put(actions.setIsLoading(false));
  }
  // return stationCode;
}

如何将站代码从那里导出到另一个组件?出口不工作 EG:出口 const stationCode = action.payload.stationCode 不工作

标签: reactjsredux-sagaredux-toolkit

解决方案


推荐阅读