Created
January 16, 2018 16:55
-
-
Save michaelnagy/1b0112fc822bef7278d49792cdca09b0 to your computer and use it in GitHub Desktop.
Redux Reselect selector to sort an array by date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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