Skip to content

Instantly share code, notes, and snippets.

@michaelnagy
Created January 16, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelnagy/1b0112fc822bef7278d49792cdca09b0 to your computer and use it in GitHub Desktop.
Save michaelnagy/1b0112fc822bef7278d49792cdca09b0 to your computer and use it in GitHub Desktop.
Redux Reselect selector to sort an array by date
import { createSelector } from 'reselect';
import moment from 'moment';
export const orderListByDate = createSelector(state => {
return state.sort((a,b) => {
return moment.utc(b.startDate).diff(a.startDate);
})
},
// the final paramenter in the createSelector
// function must be a function that accepts as arguments
// all returned results from the previous functions
result => result
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment