My goal is to extract the payload data based on a specific property.
//reducer.ts
case MessagesActionTypes.LOAD_Message_SUCCESS: {
console.log('reducer='+
JSON.stringify(action.payload.Messages));//data received here
return adapter.addAll(action.payload.Messages, state);
}
export const getSelectedMessageId = (state: MessageState) => state.selectedMessageId;
// get the selectors
const { selectIds, selectEntities, selectAll, selectTotal } = adapter.getSelectors();
// select the array of Messages
export const selectAllMessages = selectAll;
Here is the selector being used:
// Selector.ts
export const selectHomeQueues = createSelector(
fromReducer.selectAllMessages,
(messages) => messages.filter(message => message.queue === 'HOME')
);
In the reducer, I am able to receive data, but when running the selector, I encounter an error:
ERROR TypeError: Cannot read property 'map' of undefined
Note: I have not been able to locate any examples of filtering in NGRX entity selectors.
How can we effectively filter selectors in NGRX entity?