您在 Redux Observable 中需要流的地方提供了 `undefined` [英] You provided `undefined` where a stream was expected in Redux Observable
本文介绍了您在 Redux Observable 中需要流的地方提供了 `undefined`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图将我的头脑围绕在 RxJS 和 redux observable
Trying to wrap my head around RxJS and redux observable
我有这个:
export const getSomeData = (action$) =>
action$.pipe(
ofType(GET_USER_DATA),
mergeMap((action) => getData(action.id)),
map(fetchUserFulfilled),
catchError((e) =>
of({
type: 'FAILED_TO_FETCH_DATA',
e,
}),
),
)
效果很好,但现在我想在我取回数据时实际触发 2 个 observable,所以我尝试了这个:
which works good, but now I want to actually fire 2 observables when I get the data back so I tried this:
export const getSomeData = (action$) =>
action$.pipe(
ofType(GET_USER_DATA),
mergeMap((action) => getData(action.id)),
mergeMap((data) => {
const newData = data.somethingelse
of(fetchUserFulfilled(newData), anotherOne(newData))
}),
catchError((e) =>
of({
type: 'FAILED_TO_FETCH_DATA',
e,
}),
),
)
但是这是失败的.那么我该如何解决这个问题,我有什么误解,我应该如何正确使用 mergeMap
?
but this is failing. so how can I fix this and what misunderstanding am I having and how should I use mergeMap
properly?
推荐答案
mergeMap
应该返回一个 observable
mergeMap
should return an observable
mergeMap((data) => {
const newData = data.somethingelse
return of(fetchUserFulfilled(newData), anotherOne(newData))
}),
这篇关于您在 Redux Observable 中需要流的地方提供了 `undefined`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文