React native 如何根据api响应状态拦截redux传奇?
在我的react原生项目中,我希望在从api请求获得响应后全局处理204(无内容错误)响应,并导航到屏幕。如何在saga中进行拦截?您可以将api调用封装在一个bellow生成器函数中,该函数将从您的响应中拦截204,并导航到所需的屏幕React native 如何根据api响应状态拦截redux传奇?,react-native,react-navigation,redux-saga,React Native,React Navigation,Redux Saga,在我的react原生项目中,我希望在从api请求获得响应后全局处理204(无内容错误)响应,并导航到屏幕。如何在saga中进行拦截?您可以将api调用封装在一个bellow生成器函数中,该函数将从您的响应中拦截204,并导航到所需的屏幕 export function* callApi(apiCall) { const response = yield apiCall; if (!isNoContent(response)) { return respo
export function* callApi(apiCall) {
const response = yield apiCall;
if (!isNoContent(response)) {
return response;
}
//navigate to screen
return response;
}
function isNoContent(resp) {
return (
resp.status === 204
);
}
const apiCall = call(apiRequestService, payload);
const json = yield call(callApi, apiCall);
对这是一种处理响应的方法。但是,这个流程并不是我想要的。如果是这样,我必须在调用每个api请求后调用isNoContent()函数。我只想截取一些特效的传奇,如v1 beta发行说明中描述的EffectMiddleware-