Sorting on the component side vs the reducer in ngrx

2k Views Asked by At

I'm using ngrx with angular 9 in my web app. Currently im using the sortCompare function in the reducer like this:

export const adapter : EntityAdapter<Visitor> = createEntityAdapter<Visitor>({
    sortComparer: sortByLastMessage
});

All is good, however im wondering whether i should be sorting on the component side along with *ngFor loop, or keep it in the reducer. Just a question regarding the best practice.

1

There are 1 best solutions below

0
On BEST ANSWER

I wouldn't sort the state in the reducer. The selector is the right place for it (in most of the cases). The state can contain the sort config (which property and which sort order), but the logic to sort the entities should not live in the reducer imho.

https://github.com/ngrx/platform/issues/898#issuecomment-379655317