Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Created October 2, 2019 12:28
Show Gist options
  • Save alonbardavid/4ec9e70917197c313f049fdcbfe098cb to your computer and use it in GitHub Desktop.
Save alonbardavid/4ec9e70917197c313f049fdcbfe098cb to your computer and use it in GitHub Desktop.
Patterns for deriving state gist6
function sortingReducer(state,action){
const key = action.type === actionTypes.SORT_BY?action.payload:state.sortKey;
return {
list:state.list,
sorted:state.list.sort((a,b)=>a[key]>b[key]?1:a[key]<b[key]?-1:0),
sortKey:key
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment