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操作
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在rootSaga在rootSaga未被捕获
watchFecthUsers
在takeLatest
在fetUsers上
ReferenceError:错误未定义
答案 0 :(得分:0)
我知道现在回答已经很晚了,但是只是为了清楚地了解此错误
收益率看跌期权({类型:FETCTH_FAIL,错误});
在上面的行中,未定义“错误”,因此会发生错误。
您可以将此行更改为以下内容:
yield put({type:FETCTH_FAIL,error:err}); 其中'err'是catch块的变量名。