gpt4 book ai didi

syntax-error - 在rootSaga在watchSec上在rootSaga上未捕获

转载 作者:行者123 更新时间:2023-12-03 08:10:28 30 4
gpt4 key购买 nike

user.js获取用户

 import { FETCTH_FAIL, FETCTH_SUCCES, FETCTH_USER } from "../action/actionTypes";
import { put, takeLatest } from "redux-saga/effects";
import Api from "./App";

function* fetUsers() {
try {
const users = yield Api.getUsers();
yield put({ type: FETCTH_SUCCES, users: users });
} catch (err) {
yield put({ type: FETCTH_FAIL, error });
}
}

export function* watchFecthUsers() {
yield takeLatest(FETCTH_USER, fetUsers);
}
rootSaga.js rootSaga
import { call, all } from "redux-saga/effects";
import { watchFecthUsers } from "./users";

export default function* rootSaga() {
yield call(watchFecthUsers);
}
actionTypes.js Action
export const FETCTH_USER = 'fetchuser';
export const FETCTH_SUCCES = 'fetchsucces';
export const FETCTH_FAIL = 'fetchfail';
我收到下面提到的错误

D:\android_ios\sagaredux\node_modules\react-native\Libraries\Core\ExceptionsManager.js:71 uncaught at rootSaga at rootSaga

at watchFecthUsers

at takeLatest

at fetUsers

ReferenceError: error is not defined

最佳答案

我知道现在回答已经很晚了,但只是为了清楚起见,这个错误
yield put({type:FETCTH_FAIL,error});
在上面的行中,未定义“错误”,因此会发生错误。
您可以将此行更改为如下所示:
yield put({type:FETCTH_FAIL,error:err}); ,其中“err”是catch块的变量名。

关于syntax-error - 在rootSaga在watchSec上在rootSaga上未捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51983038/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com