1

I'm using react-observable and reselect in my React project. All I want to achieve is something like that:

// SELECTORS

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

and now in Epics, I want to make something like that:

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);
      },
    ),
  );

Is it somehow possible? Thank you for help!

Restir
  • 129
  • 4
  • 12

1 Answers1

0

I noticed how to use it. So if I want to receive what I've got in selector I need to do something like that:

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);
      },
    ),
  );
Restir
  • 129
  • 4
  • 12