我在redux-observable遇到问题。在调试期间,我可以看到api成功运行,但是redux-observable无法正常工作...我不知道如何解决...我尝试替换操作,没关系,但是当我替换旧操作时,我得到了一个错误。 ..
错误
TypeError: Cannot read property 'pipe' of undefined
SwitchMapSubscriber.project
src/containers/detailedProduct/DetailedProductEpic.js:27
24 |
25 | export const updateProductEpic = (action$, store$, { updateProductService }) => action$.pipe(
26 | ofType(UPDATE_PRODUCT),
> 27 | switchMap(({ payload }) => updateProductService(payload).pipe(
28 | map(res => updateProductSuccess(res)),
29 | catchError(err => updateProductFail(err)),
30 | )),
在apiService.js中
static addProduct = dataProduct => from(
axios.post(`${API}/products`, dataProduct, {
headers: {
'Content-Type': 'application/json',
},
}),
);
static updateProduct = dataProduct => {
const id = dataProduct.get('id');
from(
axios.put(`${API_LOCALHOST}/products/${id}`, dataProduct, {
headers: {
'Content-Type': 'application/json',
},
}),
);
};
在DetailedProductEpic.js中
export const addProductEpic = (action$, store$, { addProductService }) => action$.pipe(
ofType(ADD_PRODUCT),
switchMap(({ payload }) => addProductService(payload).pipe(
map(res => addProductSuccess(res)),
catchError(err => addProductFail(err)),
)),
);
export const updateProductEpic = (action$, store$, { updateProductService }) => action$.pipe(
ofType(UPDATE_PRODUCT),
switchMap(({ payload }) => updateProductService(payload).pipe(
map(res => updateProductSuccess(res)),
catchError(err => updateProductFail(err)),
)),
);
网络:api返回正常,但redux-observable无法正常工作
Request URL: http://localhost:8080/products/64a96b67-a7a9-41c4-96d6-2888b3298734
Request Method: PUT
Status Code: 200
Remote Address: [::1]:8080
Referrer Policy: no-referrer-when-downgrade
答案 0 :(得分:0)
我已经解决了这个问题...在apiservice中,我忘了在updateProduct函数中返回