Guest User

Untitled

a guest
Aug 17th, 2019
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Inside component use
  2. // const [{data}, dispatch] = useStateValue();
  3.  
  4. // REDUCER
  5.  
  6. export default function (state, action) {
  7. switch (action.type) {
  8. case "SET_DATA":
  9. return {
  10. ...state,
  11. data: action.newData
  12. };
  13. case "SET_VISIBLE_DATA":
  14. return {
  15. ...state,
  16. visibleData: action.newVisibleData
  17. };
  18. case "SET_FONT_COLORS":
  19. let newFontState = {};
  20. if (action.numberType === "odd") {
  21. switch (state.fontColors.odd) {
  22. case "black":
  23. newFontState = {
  24. ...state.fontColors,
  25. [action.numberType]: "orange"
  26. };
  27. break;
  28. case "orange":
  29. newFontState = {
  30. ...state.fontColors,
  31. [action.numberType]: "black"
  32. };
  33. break;
  34. default:
  35. break;
  36. }
  37. }
  38. if (action.numberType === "even") {
  39. switch (state.fontColors.even) {
  40. case "black":
  41. newFontState = {
  42. ...state.fontColors,
  43. [action.numberType]: "green"
  44. };
  45. break;
  46. case "green":
  47. newFontState = {
  48. ...state.fontColors,
  49. [action.numberType]: "black"
  50. };
  51. break;
  52. default:
  53. break;
  54. }
  55. }
  56. return {
  57. ...state,
  58. fontColors: newFontState
  59. };
  60. case "SET_COLUMN_SORT_DIRECTIONS":
  61. return {
  62. ...state,
  63. columnSortDirections: action.newColumnSortDirections
  64. };
  65. default:
  66. break;
  67. }
  68. };
RAW Paste Data