动作触发后如何等待Redux可观察的中间件完成

时间:2020-01-28 05:35:15

标签: redux redux-observable

GetUser操作

export const getUser = ()=>({
    type:T.GET_USER,
});

LoginUser史诗

export const getUser = (action$: any) => action$.pipe(
    ofType(T.GET_USER),
    mergeMap(({payload}) =>
        getAjax('/auth/user', 'GET').pipe(
            map(({response}) => A.getUserFulfilled(response))
        )
    )
);

我有像上面那样的动作和史诗。当我像下面那样触发动作时,我想获得Loginuser史诗结果作为如下所示的动作的返回值

// Start dispatch
const resp = dispatch(getUser())
// GET RESULTS HERE (USER variable from ajax request)
console.log(resp)

如何使用redux-observable做到这一点?

0 个答案:

没有答案