How to use the methods pop() or shift() inside of an ngrx selector?

50 Views Asked by At

Hi in my redux store a carerequest has one or more appointments, i am working with a list of carerequests where the first time a carerequest is rendered it should pick the first appointment and the second time the second appointment but we can't use pop or shift inside of our selector does anyone know a work around or how we should use pop() or shift() inside of an ngrx selector or could we dispatch an action inside of our selector?

1

There are 1 best solutions below

3
Wandrille On BEST ANSWER

pop() and shift() are mutable functions. And the state of the store should be read-only.

You can imagine something like this:

export const selectFilteredRequests = createSelector(
  selectRequests,
  (requests: Request[]) => {
     const result = [...requests];
     result.pop() // Or result.shift()
     return result
  }
);