React native React Native fetch()在第一个yield调用()之前等于false 问题是:

React native React Native fetch()在第一个yield调用()之前等于false 问题是:,react-native,fetch,redux-saga,saga,stanza.io,React Native,Fetch,Redux Saga,Saga,Stanza.io,我想添加到我的react原生项目中。经过一些研究之后,我安装了stanza.io。它似乎工作得很好,但在到达新的节代码之前就出现了一个问题:我有一个saga,它的任务是通过redux saga的yield call()触发两个同时调用fetch() const res=yield调用(fetch,fetchUrl,{method'GET',headers}) 只有第一个yield调用(fetch)失败,错误为uncaught at check call:argument false不是函数。因此

我想添加到我的react原生项目中。经过一些研究之后,我安装了stanza.io。它似乎工作得很好,但在到达新的节代码之前就出现了一个问题:我有一个
saga
,它的任务是通过redux saga的
yield call()
触发两个同时调用
fetch()

const res=yield调用(fetch,fetchUrl,{method'GET',headers})

只有第一个
yield调用(fetch)
失败,错误为
uncaught at check call:argument false不是函数
。因此,我决定在每次
产生调用(fetch)
之前
console.log(fetch)
,并发现在第一次调用之前,
fetch
等于
false
,它确实不是一个函数。但是对于之后的每个调用,fetch都工作得非常好,并且具有正确的原型,现在它又是一个函数了

我的回迁是通过以下方式触发的:

const [result1, result2] = yield all([
      call(fetch1, option),
      call(fetch2, option),
    ]);
以下是整个文件:

import { actionChannel, call, take, put, select, all } from 'redux-saga/effects';
import { device, sanitize } from 'utils';
import config from 'config';
import idx from 'idx';
import moment from 'moment';
import { TradSingleton } from 'trads';
import { LocaleConfig } from 'react-native-calendars';

function* fetchWebTrads(language) {
  try {
    const fetchUrl = `https://example.com/some_route/${language}`;
    const headers = {
      'Content-Type': 'application/json',
    };
    const res = yield call(fetch, fetchUrl, { method: 'GET', headers });
    const response = yield res.json();
    return { trad: response };
  } catch (e) {
    console.log('Error', e);
    return { trad: null, error: e };
  }
}

function* fetchMobileTrads(language) {
  try {
    const fetchUrl = `https://example.com/another_route/${language}`;
    const headers = {
      'Content-Type': 'application/json',
    };
    const res = yield call(fetch, fetchUrl, { method: 'GET', headers });
    const response = yield res.json();
    return { trad: response };
  } catch (e) {
    console.log('Error', e);
    return { trad: null, error: e };
  }
}

function* fetchTrads() {
  try {
    moment.locale('en');
    const language = device.getTradLanguage();
    const [mobileTrads, webTrads] = yield all([
      call(fetchMobileTrads, language),
      call(fetchWebTrads, language),
    ]);
    if (mobileTrads.trad && webTrads.trad) {
      moment.locale(language);
      try {
        LocaleConfig.locales[language] = {
          monthNames: moment.months(),
          monthNamesShort: moment.monthsShort(),
          dayNames: moment.weekdays(),
          dayNamesShort: moment.weekdaysShort(),
        };

        LocaleConfig.defaultLocale = language;
      } catch (e) {
        console.log('Agenda locals fail', e);
      }
      TradSingleton.setLocale(language);
      TradSingleton.setTrads([mobileTrads.trad, webTrads.trad]);
      yield put({ type: 'FETCH_TRADS_SUCCESS' });
    } else {
      yield put({
        type: 'FETCH_TRADS_FAILURE',
        error: !mobileTrads.trad ? mobileTrads.error : webTrads.error,
      });
    }
  } catch (e) {
    console.log('Error', e);
    yield put({ type: 'FETCH_TRADS_FAILURE', error: e });
  }
}

function* watchFetchTrads() {
  const requestChan = yield actionChannel('FETCH_TRADS');
  while (true) {
    yield take(requestChan);
    yield call(fetchTrads);
  }
}

export default watchFetchTrads;
软件版本:
  • 反应本机:0.57.1
  • 反应:16.5.0

您能提供更多的代码吗?我编辑了我的问题并添加了整个文件。