index.js

import { ADD_RECIPE, REMOVE_FROM_CALENDAR } from '../actions' const initialCalendarState = { sunday: { breakfast: null, lunch: null, dinner: null, }, monday: { breakfast: null, lunch: null, dinner: null, }, tuesday: { breakfast: null, lunch: null, dinner: null, }, wednesday: { breakfast: null, lunch: null, dinner: null, }, thursday: { breakfast: null, lunch: null, dinner: null, }, friday: { breakfast: null, lunch: null, dinner: null, }, saturday: { breakfast: null, lunch: null, dinner: null, }, } //Reducer Function function calendar (state = initialCalendarState, action) { const { day, recipe, meal} = action switch (action.type) { case ADD_RECIPE: return { ...state, [day]: { ...state[day], [meal]:recipe.label, } } case REMOVE_FROM_CALENDAR: return { ...state, [day]: { ...state[day], [meal]:null, } } default: return state; } } export default calendar

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.