You provided `undefined` where a stream was expected in Redux Observable

那年仲夏 提交于 2020-06-16 17:17:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!