Oblicion A
Oblicion A

Reputation: 187

Going back to basics redux

I am trying to unblock my brain around something

I have the following code

const kategorierReducer = (state = initState, action) => {
    switch (action.type) {
        case 'ADD_KATEGORI':
            console.log(action.payload)
            return [state + {action.payload}]
        case 'LOAD_KATEGORI':
            return action.payload;
        case 'EDIT_KATEGORI':
            return action.payload;
        case 'DELETE_KATEGORI':
            return null;
        default:

            return state
    }
}

And my brain is blocked around the code in the case of 'ADD_KATEGORI', how to return the current state + the new object.

help?

Btw and offtopic, is it too hard to migrate to Apollo-GraphQL?

Upvotes: 1

Views: 43

Answers (1)

andy mccullough
andy mccullough

Reputation: 9591

return [state + {action.payload}] should be return {...state, ...action.payload}

Upvotes: 3

Related Questions