是否可以从史诗中重新选择选择器?

问题描述 投票:1回答:1

我正在使用react-observable并在我的React项目中重新选择。我想要实现的就是这样:

//选择器

export const getItem = createSelector(getItemsState, state => state.item);

现在在史诗中,我想做这样的事情:

const addItem$: Epic = (action$: Observable<Actions>, state$) =>
  action$.pipe(
    filter(action => action.type === 'ADD_ITEM'),
    withLatestFrom(state$.select(getItem)), // Just use there my selector which is written.
    switchMap((item) => {
        return ItemsApi.addItem(item);
      },
    ),
  );

是否有可能?谢谢您的帮助!

reactjs redux redux-observable reselect epic
1个回答
0
投票

我注意到如何使用它。因此,如果我想接收选择器中提供的内容,则需要执行以下操作:

const addItem$: Epic = (action$: Observable<Actions>, state$) =>
  action$.pipe(
    filter(action => action.type === 'ADD_ITEM'),
    withLatestFrom(getItem(state$.value)),
    switchMap(([, item]) => {
        return ItemsApi.addItem(item);
      },
    ),
  );
© www.soinside.com 2019 - 2024. All rights reserved.