Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Created October 2, 2019 12:29
Show Gist options
  • Save alonbardavid/b01ccde58a52d3c4794fb056251f256d to your computer and use it in GitHub Desktop.
Save alonbardavid/b01ccde58a52d3c4794fb056251f256d to your computer and use it in GitHub Desktop.
Patterns for deriving state gist7
function timeRangeReducer(state,action){
let days = state.days;
if (action.type === actionTypes.SET_DAYS){
days === action.payload;
}
return {
days,
formatted: days > 14? `${Math.floor(days / 7)} weeks`:days>1?`${days} days`:'1 day'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment