Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Inside component use
- // const [{data}, dispatch] = useStateValue();
- // REDUCER
- export default function (state, action) {
- switch (action.type) {
- case "SET_DATA":
- return {
- ...state,
- data: action.newData
- };
- case "SET_VISIBLE_DATA":
- return {
- ...state,
- visibleData: action.newVisibleData
- };
- case "SET_FONT_COLORS":
- let newFontState = {};
- if (action.numberType === "odd") {
- switch (state.fontColors.odd) {
- case "black":
- newFontState = {
- ...state.fontColors,
- [action.numberType]: "orange"
- };
- break;
- case "orange":
- newFontState = {
- ...state.fontColors,
- [action.numberType]: "black"
- };
- break;
- default:
- break;
- }
- }
- if (action.numberType === "even") {
- switch (state.fontColors.even) {
- case "black":
- newFontState = {
- ...state.fontColors,
- [action.numberType]: "green"
- };
- break;
- case "green":
- newFontState = {
- ...state.fontColors,
- [action.numberType]: "black"
- };
- break;
- default:
- break;
- }
- }
- return {
- ...state,
- fontColors: newFontState
- };
- case "SET_COLUMN_SORT_DIRECTIONS":
- return {
- ...state,
- columnSortDirections: action.newColumnSortDirections
- };
- default:
- break;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement