Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const initialState = {
- "routines": {
- "1": {
- "id": 1,
- "name": "Routine 1",
- },
- "2": {
- "id": 2,
- "name": "Routine 2",
- }
- }
- }
- import { ADD_ROUTINE } from '../actions/routineActions'
- function routineReducer(state={}, action) {
- switch (action.type) {
- case ADD_ROUTINE:
- newState = {...state}
- number_of_keys = Object.keys(newState).length
- new_id = number_of_keys + 1
- return {
- ...state,
- new_id: {
- id: new_id,
- name: action.name,
- days: []
- }
- }
- default:
- return state
- }
- }
- export default routineReducer
Add Comment
Please, Sign In to add comment