Skip to content

Instantly share code, notes, and snippets.

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