问题
Trying to wrap my head around RxJS and redux observable
I have this:
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,
}),
),
)
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,
}),
),
)
but this is failing. so how can I fix this and what misunderstanding am I having and how should I use mergeMap
properly?
回答1:
mergeMap
should return an observable
mergeMap((data) => {
const newData = data.somethingelse
return of(fetchUserFulfilled(newData), anotherOne(newData))
}),
来源:https://stackoverflow.com/questions/62391509/you-provided-undefined-where-a-stream-was-expected-in-redux-observable